How does RequestManager work?

I was looking at the source for @discordjs/rest to see if I should stop the sweepers (since I only use REST, trying to keep it stateless) when I noticed sweepers that look like they handle sweeping RequestManager. I was wondering why this was needed, and looked further and found handling related to bucketing for rate-limiting (I think). I was wondering if someone could either explain, correct me, or confirm my understanding of how this system works? First of all there's not one giant RequestManager that deal with all the requests, but rather smaller units? In order to deal with Discord having endpoints it considers being "different" and those having different rate limits and groupings (buckets), the Request manager will try to create some sort of hash from the input route. We use this hash to get a small request handler unit, and if not found, we create one and cache it. The request is then queued into this handler. Each smaller handler deals with one bucket, in order to keep tracking of rate limits easily manageable. After a certain interval, sweepers will go through the cache of these smaller handlers and remove any inactive ones, or ones that are too old?
2 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Virtus
VirtusOP2y ago
If this is true, it means that my approach to make the request token agnostic by having it explicitly pass a token is going to potentially work against me? Since it could be that a route with bot token A is considered the same as with bot token B, either causing unnecessary "wait" periods, and potentially bugs where rate limiting is not handled properly hm In the future though I'm going to have to make it truly stateless (as far as it can be) by relying on Redis or so for retrieving the limits for buckets greyW thanks for your input!
Want results from more Discord servers?
Add your server