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.09k stars 2.23k forks source link

API - fetch N public study IDs/names for a user #15791

Open ddugovic opened 1 month ago

ddugovic commented 1 month ago

I have since updated the "profile" command of my Discord bot to no longer list recent public studies of a user, since I was surprised to discover that getting a list of studies (even if I only want a few) can take multiple seconds, for example (getting 400 public study IDs/names):

time curl https://lichess.org/api/study/by/ericrosen
...
curl https://lichess.org/api/study/by/ericrosen  0.13s user 0.04s system 0% cpu 20.632 total
bastianpedersen commented 1 month ago

What is the issue? The time it takes to retrieve records from the database can vary depending on how much load it is on the server.

ddugovic commented 1 month ago

The remaining issue is that using this API endpoint one could DDoS Lichess (or write an app which unintentionally generates high server load, with no option to paginate through results to improve response time).

The time to retrieve indexes scales linearly with the number of indexes to load. I used to have about 25 public studies so retrieval consistently took about 3 seconds regardless of server activity; now that I have 1 public study this request (for my username) takes under 1 second, although for users with many public studies this request takes many seconds and retrieves all the public studies of a user.