Create nowplaying/albumart
rate limiter based on current song
#249
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.
PR creates a new rate limiter that will slow down requests on the
/api/nowplaying/albumart
API. This API serves relatively large file image, so it's necessary to have a rate limiter mostly for the sake of data transfer volume.This works based on current song playing. When a new song starts, a client under a single IP can request the song's album art up to 16 times over the duration of the entire song. 16 was arbitrarily selected as an amount I expect most people to be able to comfortably pull album art under normal radio usage. We'll adjust or consider parameterizing this if necessary. If the client hits the limit before the current song ends they will receive a
304
error to indicate that Cadence will not be re-transmitting the art anymore, though the album art is still the same and it is safe to use whatever it last sent.When the current song ends, the database tracking the artwork request count is flushed and all clients reset their allowed usage of the API.