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

后端 未结 9 1534
情深已故
情深已故 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:04

    I haven't tried it, and this is an utter resource hog, but perhaps iterating with .fetch() and specifying the offset would work?

    LIMIT=1000
    def count(query):
       result = offset = 0
       gql_query = db.GqlQuery(query)
       while True:
         count = gql_query.fetch(LIMIT, offset)
         if count < LIMIT:
           return result
         result += count
         offset += LIMIT
    

提交回复
热议问题