我正在使用 Python 中的 Google App Engine 构建一个网站,但是这个问题应该适用于任何类似的东西,而不仅仅是这个特定的框架。我试图在两种相关数据模型之间做出决定。
它们涉及一个 Location 数据库类,每个 Location 实体都有多个与其挂钩的 Experience 数据库实体。
现在我在自己的内存缓存中有 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)
是否有很大的不同或我忘记了任何选择?