0

Say I have a website that has 100 products. Then this is filtered down to 5 sections containing 20 products each. If you were in one of the sections that contained 20 products (e.g. toys), what would be the optimal method to display only 5 toys per page. At the bottom of the list would be next/previous buttons to show the next/previous set of 5 toys.

A better analogy would be google search. There are millions of results but only ~10 are shown at a given time.

So right now I'm using google app engine (python) and django templates. One way I thought of to remedy this problem would be making all the query results go into a div which could then be modified through javascript to give a similar effect. However, if someone were to click their browser's back button, they wouldn't go where they originally came from.

Thanks in advance. Any help would be useful...I don't know what this technique is called so google hasn't been really useful :(

Edit: based on responses, I found my question was solved here: How to use cursor() for pagination?

Community
  • 1
  • 1
mrmo123
  • 725
  • 1
  • 8
  • 23

2 Answers2

1

Look into query cursors. Thay are made to be serialized and sent to client, to be used in creating "next" and "previous" paging requests.

NOTE: don't use offset on queries. This can be VERY expensive, as it actually fetches (and charges) all entities up to offset+limit position, but returns to application only limit results.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
0

I'm not sure that putting all the results as hidden content in the HTML and manipulating it using JS is a very good idea if you might have a large result set (think about what happened if Google used this approach). There's also the back functionality issue that you've mentioned.

So, as for querying a wanted "results page" each time, I think the Google's GQL Reference might help you, take a look specifically at the LIMIT clause, it can help you create the paging mechanism you're looking for by supplying it with the number of items-per-page you want as "count" and the numbers of items-previously-viewed as "offset" (0 at first call).

As for displaying, I think that the Google Images / Facebook News Feed approach might also be interesting to think about (loading on scroll instead of paging), but that's a matter of your personal choice :)

Hope this helps, good luck!

EDIT: After reading Peter's answer, I found it much more efficient to use cursors for pagination, a good reference is given in his answer.

Adi
  • 707
  • 6
  • 12
  • Thanks for your help! I didn't know gql had an offset clause. Based on your answer, I did a google search on `gae paging` and found this site: https://developers.google.com/appengine/articles/paging – mrmo123 Apr 21 '12 at 07:13
  • As for the facebook news feed approach, that seems like a really interesting idea. Thanks again! – mrmo123 Apr 21 '12 at 07:14
  • This article is old - don't use `offset` and `limit`. They can severely affect performance and cost. Use cursors instead. – Peter Knego Apr 21 '12 at 07:20
  • Peter I'm sorry and appreciate your answer and comment, I'm not using the LIMIT clause myself and hence wasn't aware of that performance issue, sorry. – Adi Apr 21 '12 at 07:25