What's the best way to count results in GQL?

后端 未结 9 1542
情深已故
情深已故 2020-12-02 14:21

I figure one way to do a count is like this:

foo = db.GqlQuery(\"SELECT * FROM bar WHERE baz = \'baz\')
my_count = foo.count()

What I don\'

9条回答
  •  情歌与酒
    2020-12-02 15:27

    Count functions in all databases are slow (eg, O(n)) - the GAE datastore just makes that more obvious. As Jehiah suggests, you need to store the computed count in an entity and refer to that if you want scalability.

    This isn't unique to App Engine - other databases just hide it better, up until the point where you're trying to count tens of thousands of records with each request, and your page render time starts to increase exponentially...

提交回复
热议问题