Achieve good paging using objectify

2019-07-27 02:54发布

I'm using objectify cursors to achieve basic paging, basically creating a more button.. How best do you achieve paging using objectify for building links that allow users to go forward and backwards. Something more like a page list..

1, 2, 3, 4, more

2条回答
别忘想泡老子
2楼-- · 2019-07-27 03:18

You can use cursors to create paging by one page forward and backwards, via FetchOptions.startCursor(..) and FetchOptions.endCursor(..)

To create more direct paging links you will have to use FetchOptions.limit(..) and FetchOptions.offset(..).

Note that offset(..) can be very costly as it fetches all entities that come before given page. So, depending on usage and size of the whole set, you might be better off by preloading and caching a set of keys. Or better, replace paging with search.

查看更多
3楼-- · 2019-07-27 03:19

Your best bet is probably to fetch the keys for the entire result set and stash it in a session or in javascript. Each next/previous can load the next item in your list by id. Loading by id is very cheap. You can cache the full query results in memcache as long as it's not too large but that's going to depend on what kind of objects you're fetching.

查看更多
登录 后发表回答