[google-appengine] Confuse about which is better solution to pagination using datastore on Python App Engine

2015-07-06 Thread Zeck Li
Hi, 
I'm building a Webapp2 application, and trying to find the best solution 
for pagination.
I found out that the prevalent solution is to use the cursor. For example:

# In my opinion, I think that I need to get all cursors in the very first 
time
# For example, there will be 2 cursors for 3 pages 
# page1|c1|page2|c2|page3

page_size = 20
all = model.MyModel.gal(...)

# Client will send the page number in order to get cursor from the memcache
...

if has cursor:
   # Use cursor to get items
   list = all.with_curosr(...)
else:
   # Get all cursors and memcaching all cursors
   ...

I also tried another solution although I knew many people will consider it 
a bad solution:

# In this solution, I try to split query into many list
# page1(list1)|page2(list2)|page3(list3)

page_size = 20
all = list(model.MyModel.gql(...))
lists = [all[i:i+page_size] for i in range(0, len(all), page_size)]

# Client will send the page number
...

list = []
if len(lists)  0:
list = lists[int(page_number)-1]


Here comes my question. What is the advantages of using cursor ?
Both two solutions all need to execute MyModel.gql(...) to get all data, 
and the first solution still need to execute with_cursor(...) to retrieve 
items.
It makes me so confused.

If you have better solutions or any suggestions for improving my solution, 
please share with me !!

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/9afe6644-db6e-461a-aaca-e5990da0d6c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [google-appengine] Confuse about which is better solution to pagination using datastore on Python App Engine

2015-07-06 Thread Karl MacMillan
  

 On Jul 6, 2015, at 4:22 AM, Zeck Li hatemegal...@gmail.com wrote:
 
 
 Here comes my question. What is the advantages of using cursor ?
 Both two solutions all need to execute MyModel.gql(...)to get all data, and 
 the first solution still need to execute with_cursor(...)to retrieve items.
 It makes me so confused.
 
 
 
 

In the most basic terms, when you use a cursor the query can start from where 
it left off. With your other solution it will have to execute a new query, 
start the beginning of the results, and seek until it gets to the starting 
point for that page. If you are deep into a result set that seeking can waste 
quite a bit of time.


Karl


 If you have better solutions or any suggestions for improving my solution, 
 please share with me !!
 
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to google-appengine+unsubscr...@googlegroups.com
 .
 To post to this group, send email to google-appengine@googlegroups.com
 .
 Visit this group at http://groups.google.com/group/google-appengine
 .
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-appengine/9afe6644-db6e-461a-aaca-e5990da0d6c6%40googlegroups.com
 .
 For more options, visit https://groups.google.com/d/optout
 .

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CCC309D9-139B-434D-9DFD-C76332CE1117%40rakkoon.com.
For more options, visit https://groups.google.com/d/optout.