MT-CTF/capturetheflag

Restructuring rankings saving mechanism for better efficieincy and accessibility

farooqkz opened this issue · 2 comments

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:

  • lookup of player by name/nick in constant time(O(1)) using ZSCORE
  • lookup of player by rank is also done in constant time
  • most other operations are O(log(n))

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.

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

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.