ppy / osu-web

the browser-facing portion of osu!
https://osu.ppy.sh
GNU Affero General Public License v3.0
976 stars 380 forks source link

Extend API getters GET USER and GET USERS by Rank #10781

Open takoz53 opened 10 months ago

takoz53 commented 10 months ago

Problem get_user: Currently get_user uses an id or the username of an user to find their data and lastly yield back an User object. The issue here is that there is no reliable way to look up a player by rank. The only way to reliably look up for players by rank currently is by scraping it from the website by trying every single ID. This is probably not in interest for osu! and developers as it's a demerit for both sides (scraping sucks; Unnecessary traffic is bad for osu!). There is also one way to look up the top 10000 players by using the performance rankings and by filtering by page. There is sadly only 200 pages (thus 10 000), so we will never know about the other million of players. This was also requested for a longer time by multiple users, also visible in the forum. As an example, we can take this forum post from roughly a year ago.

Proposal: Implementing a new key to look up for rank instead. key: { id: string, username: string, rank: string, } If key is not given, ID lookup is prioritised as usual.

By doing so, we can search for specific ranks. By calling e.g. GET "https://osu.ppy.sh/api/v2/users/1/osu?key=rank", we will get mrekk his User object (as of 03.12.2023).

Problem get_users: Currently, get_users uses multiple ids to find multiple users and yields multiple User objects back. The issue here is that there is no reliable way to look up multiple players by rank.

Proposal: Extend get_users by an optional key key: { ids: string, ranks: string } If key is not given, IDs lookup is prioritised.

By doing so, we can e.g. get all top players from 1 to 50 by calling GET "https://osu.ppy.sh/api/v2/users?ranks%5B%5D=1,2,...,50". This will yield back an Array of User Objects, containing rank 1 to 50.

peppy commented 10 months ago

This isn't indexed at the database, so would be quite an involved change.

takoz53 commented 10 months ago

This isn't indexed at the database, so would be quite an involved change.

I do not understand why it is quite an involved change. This would just require to index it at the database (which will require computing power, not a lot of changes from the developer side), implementing a new key compatibility in the API and creating a query for the key to get the new data.

Am I missing something here?

tybug commented 9 months ago

duplicate of https://github.com/ppy/osu-web/issues/7374 (but this issue should probably be kept open instead, as it has more detail).