MT-CTF / capturetheflag

Capture the Flag game using the Minetest Voxel Engine
https://ctf.rubenwardy.com
80 stars 85 forks source link

Restructuring rankings saving mechanism for better efficieincy and accessibility #1282

Open farooqkz opened 3 months ago

farooqkz commented 3 months ago

Currently the rankings are stored in Redis in a really bad manner. shangul is a stringified json. I propose to save rankings in a sorted set for more efficiency during lookups. Benefits include:

However the disadvantage exists that the current implementation does increasing score by O(1). But the current implementation has a very inefficient way of looking up a range. e.g. top100, bottom100(!) and so on.

@LoneWolfHT If I have your approval, I will start this transition with the rankings api on the test server.

LoneWolfHT commented 3 months ago

Make sure to do this by creating a new ranking backend, don't overwrite anything redis, and let me know if the code on top of the backends needs changing

savilli commented 2 months ago

the current implementation has a very inefficient way of looking up a range

That's not exactly true. We already have a sorted set at home - ctf_rankings/top.lua file. All rank lookup operations use it and don't make requests to redis.

lookup of player by rank is also done in constant time

I'm sure it's O(log(n)). In practice the difference between O(1) and O(log(n)) is negligible tho.