Python で Google App Engine を使用して Web サイトを構築していますが、この質問は、この特定のフレームワークだけでなく、同様のものにも当てはまるはずです。関連データの 2 つのモデルのどちらかを決定しようとしています。
それらには Location データベース クラスが含まれ、各 Location エンティティには複数の Experience データベース エンティティがフックされています。
現在、独自の memcache に 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 に対して 2 つの呼び出し (1 つは場所用、もう 1 つはすべての呼び出し) を行う方がよいかどうか疑問に思っています。そこでの経験。
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)
大きな違いや忘れているオプションはありますか?