App: Fix rate limit when having much relationships #22352
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Scope
When there's much different relationships1 configured on the collection, we sometimes see the following error while navigating in the App:
The requests come from server with status 429 Too Many Requests. This is because rate limiter is set to 50 points for 1 second and the requests from App are going beyond this.
After looking into this, we saw Directus App using
p-queue
in order to prevent this rate limit errors.Although, the way it's configured does not seem right as we still see issues.
The current configuration sets the
intervalCap
toRATE_LIMITER_POINTS - 10
andinterval
toRATE_LIMITER_DURATION
.This seems right, but since the duration is too long, some requests may start after hitting the rate limit on the server.
In this PR, we change the way this is configured.
To prevent the issue mentioned above, we do the math to get the smallest interval possible. In other words, we set
intervalCap
to 1 and theinterval
toRATE_LIMITER_DURATION / RATE_LIMITER_POINTS
which will give the interval for 1 point.What's changed:
Potential Risks / Drawbacks
Review Notes / Questions
Reproduction
before.mov
after.mov
Use the following database dump to reproduce the issue:
app_fix-rate-limit.sql.zip
Then navigate between items in different collections and items in collection
e
Footnotes
I was not able to determine the amount but it is dependant on the values configured for the rate limiter ↩