etc*_*etc 5 google-app-engine google-cloud-datastore
我已经在多个位置读过GAE提高了查询和计数的1000记录限制,但是,我似乎只能得到高达1000的记录数.我不会一次提取超过1000个查询,但要求是我需要计算匹配的记录.
我知道你可以使用游标通过数据集"分页",但循环只是为了获得计数似乎有点多.大概是当他们说他们"解除"限制时,这是一个硬限制 - 你仍然需要一次循环1000个结果,我是否正确?
我应该使用除.all()/ filter方法之外的方法来生成1000+计数吗?
在此先感谢您的帮助!
Query.count()当没有明确指定限制时,行为与文档不一致 - 文档表明它将计数"直到它完成计数或超时".GAE 问题3671报告了这个错误(大约3周前).
解决方法:明确指定限制,然后使用该值(而不是默认值1,000).
在http://shell.appspot.com上进行测试证明了这一点:
# insert 1500 TestModel entites ...
# ...
>>> TestModel.all(keys_only=True).count()
1000L
>>> TestModel.all(keys_only=True).count(10000)
1500L
Run Code Online (Sandbox Code Playgroud)
我还使用这个简单的测试应用程序在最新版本的开发服务器(1.3.7)上看到了相同的行为:
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1430 次 |
| 最近记录: |