stadust / pointercrate

Rewrite of the https://pointercrate.com backend in Rust
MIT License
79 stars 52 forks source link

Rank should be included in full form of player #163

Open yuyuko-s opened 1 month ago

yuyuko-s commented 1 month ago

The full form of a player doesn't include their stats viewer rank. Currently, I have to make two separate requests to get a player's records and a player's rank.

stadust commented 4 weeks ago

Hi, this is because the rank is not actually stored anywhere, but rather its computed on the fly when doing a request to the /ranking endpoint. So this is sadly a bit more complicated than just adding a new field to the API response, as it'd require us to cache the rank.

yuyuko-s commented 3 weeks ago

Thanks for the quick response. You mentioned in the /ranking/ documentation that the endpoint is relatively slow. Perhaps it would be faster to cache the rank anyways? Instead of calculating the ranks every time someone makes a request to /ranking/, you would only have to calculate the rank when a record is added, player is banned etc.

stadust commented 2 weeks ago

Thanks for the quick response. You mentioned in the /ranking/ documentation that the endpoint is relatively slow.

Ah, funnily enough that's outdated, because nowaday the response to that endpoint is mostly cached

Perhaps it would be faster to cache the rank anyways? Instead of calculating the ranks every time someone makes a request to /ranking/, you would only have to calculate the rank when a record is added, player is banned etc.

We already cache the score, so most of the infrastructure for when to trigger updates to the cached values would already be there.

That said, wouldn't you need two requests anyway? One to resolve the player name to an ID and then another to grab the records?

yuyuko-s commented 2 weeks ago

Hi, thanks for the information about this issue. To answer your question, I only store players by their ID. The only time I have to resolve an ID from a name is when users search for a player by their username, but I almost always have player information cached. Having the rank included in the full form of a player would make it so I would only need one request to cache a player rather than two.

stadust commented 1 week ago

Ah, I see. Yes, that sounds valid. @emonadeo at some point mentioned overhaulting this all with materialized views to implement #132, so probably including rank can be done as part of that :)