1 Counting
Every time, Google App Engine releases new version of SDK, I always read the release notes. I was aware of
Results of datastore count() queries and offsets for all datastore queries are no longer capped at 1000,
when version 1.3.6 was released. I wrote a quick code to test it, something like the followings:
count = TestModel.all().count()
data1 = TestModel.all().fetch(1100, offset=5)
data2 = TestModel.all().fetch(1, offset=1100)
Using 1.3.8, first part still got me 1000 at most. The second part, I could fetch more than 1000 entities, and the offset could be bigger than 1000 without problems.
I finally saw someone asked and the correct way is:
count = TestModel.all().count(limit=None)
Now, I am reading the documentation again:
count() has no maximum limit. If you don’t specify a limit, the datastore continues counting until it finishes counting or times out.
This doesn’t sound like the same behavior in development server. I didn’t try it on production server.
(I used to use this way to count.)
2 Randomly fetching
Before 1.3.6, there are some ways to get a random entity from datastore. All suck and are awkward. Now offset can be supplied with number bigger then 1000. Does it resolve? Read this line first:
The query has performance characteristics that correspond linearly with the offset amount plus the limit.
Well, I don’t care at this moment since none of my data are too large.
I think Google is Einstein and Google App Engine is Quantnum Theory. ;)
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.