Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Discord we hit an API throttling #167

Open
damienalexandre opened this issue Oct 28, 2020 · 2 comments
Open

On Discord we hit an API throttling #167

damienalexandre opened this issue Oct 28, 2020 · 2 comments

Comments

@damienalexandre
Copy link
Member

Not the same as #153

An error occurs in production:

Client error: GET https://discordapp.com/api/v6/guilds/***/members?limit=200&after=*** resulted in a 429 Too Many Requests response.

I thing that when we fetch the members of the guild we should be less agressive in the for loop.

do {
if ((time() - $startTime) > 19) {
throw new UserExtractionFailedException(DiscordApplication::APPLICATION_CODE, 'Took too much time to retrieve all the users on your team.');
}
$lastMember = $lastMembers ? end($lastMembers) : null;
try {
/** @var GuildMember[] $members */
$lastMembers = $this->apiHelper->getMembersInGuild($guildId, $lastMember ? $lastMember->user->id : null);
} catch (\Throwable $t) {
throw new UserExtractionFailedException(DiscordApplication::APPLICATION_CODE, 'Could not fetch members in guild.', $t);
}
$members = array_merge($members, $lastMembers);
} while (!empty($lastMembers));

Adding a "sleep" maybe?

There is also a lot of headers to help us mitigate this issue: https://discord.com/developers/docs/topics/rate-limits

@damienalexandre
Copy link
Member Author

Looks like it will be available directly in Symfony 5.2 symfony/symfony#38182

@damienalexandre
Copy link
Member Author

The patch did not work, we still have this issue of big teams.

I don't have time right now to investigate more, feel free to take over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant