Google App Engine-获取符合条件的记录数超过1000 [英] Google App Engine - getting count of records that match criteria over 1000

查看:77
本文介绍了Google App Engine-获取符合条件的记录数超过1000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在多个地方都读过,GAE取消了1000条记录和查询记录的限制,但是,我似乎只能获得最多1000条记录的记录.在这里,我不会拉出1000条以上的查询时间,但要求是我需要对匹配记录进行计数.

I've read in multiple locations that GAE lifted the 1000 record limit on queries and counts, however, I can only seem to get a count of the records up to 1000. I won't be pulling more than 1000 queries at a time, but the requirements are such that I need a count of the matching records.

我知道您可以使用游标在数据集中进行分页",但是为了获得计数而进行循环似乎有点多.大概当他们说他们提高"了限制时,那是硬性限制-您仍然需要一次循环搜索结果1000,对吗?

I understand you can use cursors to "paginate" through the dataset, but to cycle through just to get a count seems a bit much. Presumably when they said they "lifted" the limit, it was the hard limit - you still need to cycle through the results 1000 at a time, am I correct?

是否应该使用.all()/filter方法以外的方法来生成1000多个计数?

Should I be using a method other than the .all()/filter method to generate 1000+ counts?

在此先感谢您的帮助!

推荐答案

Query.count() 与文档不一致-文档指出它将计数为直到计数结束或超时". GAE 问题3671 报告了此错误(大约3周前).

The behavior of Query.count() is inconsistent with the documentation when no limit is explicitly specified - the documentation indicates that it will count "until it finishes counting or times out." GAE Issue 3671 reported this bug (about 3 weeks ago).

解决方法:明确指定一个限制,然后使用该值(而不是默认值1,000).

The workaround: explicitly specify a limit and then that value will be used (rather than the default of 1,000).

http://shell.appspot.com 上进行的测试证明了这一点:

Testing on http://shell.appspot.com demonstrates this:

# insert 1500 TestModel entites ...
# ...
>>> TestModel.all(keys_only=True).count()
1000L
>>> TestModel.all(keys_only=True).count(10000)
1500L

在使用此简单测试应用程序的最新版本的开发服务器(1.3.7)上,我也看到了相同的行为:

I also see the same behavior on the latest version of the development server (1.3.7) using this simple test app:

from google.appengine.ext import webapp, db
from google.appengine.ext.webapp.util import run_wsgi_app

class Blah(db.Model): pass

class MainPage(webapp.RequestHandler):
    def get(self):
        for i in xrange(3):
            db.put([Blah() for i in xrange(500)])  # can only put 500 at a time ...
        c = Blah.all().count()
        c10k = Blah.all().count(10000)
        self.response.out.write('%d %d' % (c,c10k))
        # prints "1000 1500" on its first run

application = webapp.WSGIApplication([('/', MainPage)])

def main(): run_wsgi_app(application)
if __name__ == '__main__': main()

这篇关于Google App Engine-获取符合条件的记录数超过1000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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