I realized one thing..

q=Somemodel.all()
q.filter(some cursor compatible filters)  # if needed
....
.... # anything here but dont set cursor on the query
q.keys_only=True
temp=q.fetch(1,999)
q.with_cursor(q.cursor)
item=q.fetch(1,999)


Will get you 2000th element.
Using this technique(as long as number of elements per page is a
factor of 1000), you can calculate pagination using normal offsets,
but if it crosses 1000 you split the offsets into 1000s place  and the
rest (using integer division and modulo by 1000) . You jump towards
the nth 1000 using the above technique .. then make a final finetuning
fetch .. example will clearly demo what I say:

suppose you want the 226th page with 20 elements per page

######################
page=226
itemsperpage=20

q=SomeModel.all()
q.filters(some cursor compatible filters)
....
.... # anything here but dont set cursor manually on the query
q.keys_only=True

offset=page*itemsperpage   # in this case 4520

new_offset=offset % 1000
for i in xrange(0,offset/1000):
      q.fetch(1,999) ## we dont assign it because we want to discard
item_keys=q.fetch(itemsperpage,new_offset)

items=db.get(item_keys)
##############

With some smart use of memcache, not so many jumps would be needed
either.
(If someone comes  up with a good paginator function or class *with
memcaching*, please post :) )

Pros of this method:
   *   You can use numbers directly in the urls instead of cursors and
the like :) This makes generating pagination links (First Prev , 1,
2,3 ... 350 Next Last) a breeze while still being able to go beyond
1000 offset limit.
   *   You can use this method with almost any cursor friendly query
   *   Cursors come into picture only if you have more than 1000
items.

Cons of this method
   *  Items per page are limited to factors of 1000 (must be
validated!)
   *  If users often access items beyond 5000 items, it can still have
an impact on performance????

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to