【发布时间】:2012-03-06 15:44:51
【问题描述】:
我正在使用 python 27 在 appengine 上制作一个基本相册。我编写了以下方法来从与特定“冒险”匹配的数据存储中检索图像细节。我使用限制和偏移量进行分页,但是效率很低。浏览 5 页(每页 5 张照片)后,我已经使用了 16% 的 Datastore Small Operations。有趣的是,我只使用了 1% 的数据存储读取操作。我怎样才能使数据存储小型操作更有效 - 我不确定它们是由什么组成的。
def grab_images(adventure, the_offset=0, the_limit = 10):
logging.info("grab_images")
the_photos = None
the_photos = PhotosModel.all().filter("adventure =", adventure)
total_number_of_photos = the_photos.count()
all_photos = the_photos.fetch(limit = the_limit, offset = the_offset)
total_number_of_pages = total_number_of_photos / the_limit
all_photo_keys = []
for photo in all_photos:
all_photo_keys.append(str(photo.blob_key.key()))
return all_photo_keys, total_number_of_photos, total_number_of_pages
【问题讨论】:
标签: python google-app-engine google-cloud-datastore python-2.7