How to save an ordered list in the AppStore DataStore, how does each object know its position in the list?

I have a rating of people based on the points they earn. I need to tell each participant about their position in the game, for example, John (1) - 170 points, Mary (2) - 160 points, Sarah (3) - 110 points

So John is the first, Mary is the second, and Sarah is the third. Now, if Mary wins another 20 points, she will be the first, and John will be the second.

I try to avoid having to run a task in cron to list and recount all positions.

My first attempt was to maintain a separate entity set (PersonRank) so that I would not encounter transaction problems, this rank would have the same key name, so I could use db.get () on the key. This person would have a person designed for ranking, so when a person receives points, I will need to check whether the next person on the line has fewer points than me, and change places with me so that it is true. The problem is that Sarah, for example, may have won 100 points, and is now number one. In the previous algorithm, I would have to “walk” among many entities, which means that many DataStore get and put (updating each Entity involved in a new position).

My next guess is perhaps some sort of linked list with ReferenceProperties, perhaps using key names to indicate position.

Any tips on how to implement this?

+3
source share
2 answers

Much more complicated than me, but I hope some guys from Google have already implemented this solution - http://googleappengine.blogspot.com/2009/01/google-code-jams-ranking-library.html

0
source

As you yourself answered 3 years ago, Google implemented this solution, but they did it exclusively for Python. An unofficial Java solution, someone renamed the Python solution and decided to share it: http://toolongdidntread.com/google-app-engine/using-googles-datastore-to-implement-a-ranked-scoreboard/

, , . , . , Java, Python 3 / (!).

: https://cloud.google.com/developers/articles/fast-and-reliable-ranking-in-datastore/

, , Google , 300 , , -, , , . , Python, .

- , , , .

0
source

Source: https://habr.com/ru/post/1791087/


All Articles