Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google AppEngine: how to count a database's entries beyond 1000?

Duplicate of "how does one get a count of rows in a datastore model in google appengine?"


I want to know how many users I have. Previously, I achieved this with the following code:

users = UserStore.all()
user_count = users.count()

But now I have more than 1,000 users and this method continues to return 1,000.

Is there an efficient programmatic way of knowing how many users I have?

like image 635
Manuel Araoz Avatar asked Apr 28 '09 00:04

Manuel Araoz


2 Answers

It is indeed a duplicate and the other post describes how to theoretically do it, but I'd like to stress that you should really not be doing counts this way. The reason being that BigTable by its distributed nature is really bad for aggregates. What you probably want to do is add a transactional counter to that entity, and if there are lots of transactions a sharded counter. See: http://code.google.com/appengine/articles/sharding_counters.html

UPDATE: Since 1.3.1 cursors make stuff like this a lot easier: http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors

like image 53
Koen Bok Avatar answered Oct 20 '22 00:10

Koen Bok


Use pagination like these examples here.

like image 27
Bjorn Avatar answered Oct 20 '22 00:10

Bjorn