开发者

Replicated data vs. Multiple searches on Google App Engine - Design decision

开发者 https://www.devze.com 2023-03-20 10:34 出处:网络
I always catch myself with this problem with Google App Engine: should I repeat data that is stored in other entities or should I make associations? What should I analyze to make this decision?

I always catch myself with this problem with Google App Engine: should I repeat data that is stored in other entities or should I make associations? What should I analyze to make this decision?

I won't use this information on searches, so it's not the "GAE join problem", it's a matter of co$t.

Right now, I have something like this rugged example:

public class GameResult
{
    priv开发者_运维知识库ate int points;
    private int duration;
    ...
}

public class Player
{
    private string name;
    private GameResult lastGameResult;

    List<int> lastGamesPoints;
}

Somehow I need to know the punctuation of the last 5 games and that's the only information I need, that is, I don't need to know other stuff about GameResult of past games. I could have this List of ints or I could have a OneToMany association of GameResults.


It really depends on your real usage and bottleneck. If you don't need to modify these data, duplicate them to different entities will be a good idea. Especially while you need to fetch these "last five results" (an query with order_by). If you use the one-to-many relation model, that mean you need to cost some CPU hour to index them first. Then you need to pay extra CPU hour on query these results. I don't think it is a good idea. Another way to do it will be use a ListProperty to store the last five GameResult entities. It implies that you can retrieve these entities with their keys which will be faster than query.

For more information, there are some great posts to read! Relational vs Non-Relational Data Modeling - what's the difference & How to think in data stores instead of databases?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号