use*_*852 2 python google-app-engine python-2.7 google-cloud-datastore
我正在使用python 27在appengine上组合一个基本的photoalbum.我已经编写了以下方法来从数据存储中检索匹配特定"冒险"的图像细节.我正在使用限制和偏移进行分页,但效率非常低.浏览5页(每页5张照片)后,我已经使用了16%的数据存储小型操作.有趣的是,我只使用了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
Run Code Online (Sandbox Code Playgroud)
一些东西:
挑剔:你不需要the_photos = None
| 归档时间: |
|
| 查看次数: |
1410 次 |
| 最近记录: |