我的代码分批从数据存储中获取结果,并检测何时到达末尾。如何实际重置或删除光标,以便下一次从查询的开头开始?
q = Company.all()
q.order("datetime")
company_cursor = memcache.get("company_cursor")
if company_cursor:
q.with_cursor(start_cursor = company_cursor)
chunk_size = 5
companies = q.fetch(chunk_size)
for company in companies:
do_stuff(company)
if len(companies) < chunk_size:
# This is where I want to reset, or remove, the cursor.
memcache.add("company_cursor",company_cursor, 11000) # 10800 == 180 min.
company_cursor = q.cursor()
memcache.set("company_cursor",company_cursor, 11000)