Google AppEngine:如何计算数据库的条目超过1000? [英] Google AppEngine: how to count a database's entries beyond 1000?

查看:185
本文介绍了Google AppEngine:如何计算数据库的条目超过1000?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复 如何获取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()

但现在我有超过1,000个用户,此方法继续返回1,000。

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?

推荐答案

它确实是一个重复,其他帖子描述如何从理论上做,但我想强调,你应该真的不应该这样计数。原因是BigTable的分布式本质对于聚合是非常糟糕的。你可能想要做的是向该实体添加一个事务计数器,并且如果有很多事务一个分片计数器。请参阅: http://code.google.com/appengine/articles/sharding_counters.html

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

更新:由于1.3.1游标使这样的东西更容易: http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors

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

这篇关于Google AppEngine:如何计算数据库的条目超过1000?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆