代码之家  ›  专栏  ›  技术社区  ›  Ivo Danihelka

Optimizing appengine entity key usage

  •  3
  • Ivo Danihelka  · 技术社区  · 16 年前

    Should I care about locality of entities on the Google App Engine datastore? Should I use custom entity key names for that?

    For example, I could use "$article_uuid,$comment_id" as the key name of a Comment entity. Will it improve the speed of fetching all comments for an article? Or is it better to use shorter keys?

    Is it a good practice to use the key in this way? 我可以使用 "$article_uuid,$comment_id" key name also instead of an index:

    def get_comments(article_uuid, limit=1000):
        key_prefix=db.Key.from_path('Comment', article_uuid)
        q = Comment.gql("where __key__ > :key_prefix and __key__ < :range_end",
            key_prefix=key_prefix, range_end=key_prefix+chr(ord(',')+1))
        return q.fetch(limit)
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   David Underhill    16 年前

    The locality of your data will be improved with your key_name 方案(方案) ref, see slide 40 -因为你 密钥名 is prefixed with the corresponding article's ID, comments for a given article should be stored near each other.

    这个 密钥名 you proposed doesn't seem like it would be too long. I don't think you'll see too much difference between that and shorter keys in terms of storage space or serialization/deserialization time. 我希望 Comment entity will be dominated by the rest of the entity.