0
我正在Python中使用Google App Engine構建網站,但這個問題應該適用於任何類似於這個特定框架的類似問題。我正試圖在兩種相關數據模型之間做出決定。相關數據條目的最有效途徑
它們涉及一個Location數據庫類,每個Location實體都有多個與其掛鉤的Experience數據庫實體。
現在我在他們自己的memcache中擁有Locations類,並且我引用了存儲在expRef IntegerProperty中的每個Experience。然後,我執行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))
我想知道如果這是最好的選擇,或者倒不如給每個體驗到的位置屬性的引用,然後存儲所有Memcached中的引用,使兩個調用memcached的,一個是地點,然後是所有在那裏的經驗。
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)
有沒有很大的差異或任何選項我忘了?
使用代碼來定義問題總比使用自然語言更容易,您能提供一些您寫的內容的代碼以及您正在考慮的內容嗎? – bigblind
好吧我認爲這應該有所幫助 – clifgray