Google App Engine Datastore entities. Efficiency and structure

走远了吗. 提交于 2019-12-13 07:13:31

问题


I am interested in knowing the best structure, for speed and cost efficiency, of Google App Engine Datastore entities.

As an example, an app about Clubs.

Structure A:

A single ndb.Model entity per club with: Name, ID, Address, Contacts, Tags, Reviews, Images etc

Structure B:

Multiple Entities per club with a KeyProperty referencing the club.

  1. ndb.Model Entity A. Name and ID
  2. ndb.Model Entity B. Address
  3. ndb.Model Entity C. Contacts
  4. etc

Considering that users might only want to look up addresses of Clubs close to their location, or perhaps only search for a contact number for one Club, or might scroll through pages of information about various Clubs; what is the better structure / best practice for speed and cost efficiency?

Thanks.


回答1:


It all boils down to (a) reading pattern, and (b) writing pattern.

READ: If your most widely use-case is to show all the information about the club, keeping all information in a single entity will be a cheaper and a more efficient approach (one read instead of three).

WRITE: If your model includes many properties that are almost never changed and some properties that change very frequently, it's better to separate them into different entities, so that each update of a single entity does not trigger updates to all indexes.

It appears that in your example there are no reasons to split the entity into multiple models.




回答2:


Structure B, but all the extra models added as Structured Properties.

That will make the whole club a single entity



来源:https://stackoverflow.com/questions/36582513/google-app-engine-datastore-entities-efficiency-and-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!