1

docs,我知道Query.run()返回一个可迭代并Query.fetch()返回一个列表。文档说这fetch()只是一个包装器,run()通常不应该使用,因为它更占用内存。但是根据我的(有限的)经验,他们做同样的事情:他们让你循环你的查询结果。为什么fetch()存在?它有什么用,它在做什么,效率低于run()

4

1 回答 1

2

run() returns an iterable that issues async calls as needed to pull data from the datastore as you iterate through your items. If you don't iterate through your entire result set, it may not return all the entities in the result set.

fetch() essentially calls run(), iterates through the entire result set and places all the results in a list.

If you use fetch(), you'll get the list back and then iterate through it again.

fetch() tends to be beneficial in cases where you absolutely, must get all your data in a list and operate on a list.

于 2013-07-02T16:50:13.383 回答