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

查看:18
本文介绍了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天全站免登陆