【发布时间】:2012-10-07 06:17:09
【问题描述】:
我正在使用 Python 中的 Google App Engine 构建一个网站,但这个问题应该适用于任何类似的东西,而不仅仅是这个特定的框架。我试图在两种相关数据模型之间做出决定。
它们涉及一个位置数据库类,每个位置实体都有多个与其挂钩的体验数据库实体。
现在我在自己的内存缓存中有 Locations 类,并且我引用了存储在 expRef IntegerProperty 中的每个体验。然后我执行 Experience.get_by_id(expRef) 以获取所有体验并将它们显示在位置页面上。
class Location(ndb.Model):
#a bunch of other properties
expRefs = ndb.IntegerProperty(repeated=True)
class Experience(ndb.Model):
#a bunch of other properties with no ref to Location
#here is the handler for the Location page
location = individual_location_cache(keyid)
exps= []
if location.expRefs != []:
for ref in location.expRefs:
records.append(Record.get_by_id(ref))
我想知道这是否是最好的选择,或者最好给每个体验一个 Location 属性的引用,然后将所有引用存储在 Memcached 中,并对 memcached 进行两次调用,一次调用 Location,然后调用那里的所有体验。
class Location(ndb.Model):
#a bunch of other properties but no ref to experiences
class Experience(ndb.Model):
#a bunch of other properties
locationRef = ndb.IntegerProperty()
#the Location page handler starts here
location = individual_location_cache(keyid)
exps= exp_location_cache(keyid)
是否有很大的不同或我忘记了任何选项?
【问题讨论】:
-
用代码定义你的问题总是比用自然语言更容易,你能提供一些你写的代码和你正在考虑做什么的代码吗?
-
好吧,我觉得应该有点帮助
标签: python database google-app-engine optimization google-cloud-datastore