lichess-org / lila

♞ lichess.org: the forever free, adless and open source chess server ♞
https://lichess.org
GNU Affero General Public License v3.0
15.65k stars 2.28k forks source link

Get titled users API is slow when requesting only online players #4849

Closed typescriptstudies closed 5 years ago

typescriptstudies commented 5 years ago

https://lichess.org/api/users/titled?titles=BOT,GM,WGM,IM,WIM,FM,WFM,CM,WCM,NM,WNM,LM&online=true

The above request was intended to query all online titled players. When tested it returned 74 players ( 5 kB in size ). Yet it took a long time for it to load, on the order as if I have requested all titled players regardless of online status ( which is 2216 players, more than 100 kB in size ).

However the below query is very fast ( note that there are only 2 WNMs ):

https://lichess.org/api/users/titled?titles=WNM&online=true

The documentation on the real time users API ( https://lichess.org/api#operation/apiUsersStatus ) says that this API is cheap on lichess side. So there must be a way to return online titled players faster ( I mean do the search based on online players and fetch titled out of them, rather than fetching all titled players and see which are online ).

ornicar commented 5 years ago

There are 2,216 titled players and up to 40,000 online players.

typescriptstudies commented 5 years ago

I'm not aware how things are implemented, but if online players are kept in memory and titled players require database query, then fetching online titled from memory may be faster.

ornicar commented 5 years ago

It's not. Fetching 40,000 players is slower than fetching 2216.