Skip to content

Fix large blocked users list preventing login #175

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

Merged
merged 2 commits into from
Aug 5, 2022

Conversation

tommyxchow
Copy link
Owner

@tommyxchow tommyxchow commented Aug 5, 2022

Fixes #169.

Thanks to the detailed reporting in #169, we were able to discover that having a really large list of blocked users was blocking the UI and preventing the login from completing properly.

The cause

After logging in, there is an initialization process that involves fetching information regarding the logged-in user. These steps are performed sequentially through fetching with await, so the next steps must wait for the previous ones to complete.

When fetching blocked users, the logged-in user could have thousands, if not, hundreds of thousands of blocked users (one reason being bots). This will cause "jank" and essentially freeze the UI until all users have been fetched.

Furthermore, the Twitch API only allows fetching up to 100 blocked users per request, with a limit of 800 requests per minute. Therefore, when too many blocked users are fetched, it will prevent the login initialization from completing.

The fix

In order to fix this, I've removed await from the request and have opted for a normal async future with a completion handler. This will prevent the main thread from being blocked and perform the request in the "background".

To account for the 100 blocked users per request and the Twitch API limit, I've added a delay of 150 milliseconds between each request. This means that total requests for blocked users are capped at 400 per minute, half of the 800 per minute cap previously mentioned. Theoretically, this will prevent requests from throwing a rate limit error.

@tommyxchow tommyxchow added the bug fix A fix for a bug label Aug 5, 2022
@tommyxchow tommyxchow self-assigned this Aug 5, 2022
@tommyxchow tommyxchow linked an issue Aug 5, 2022 that may be closed by this pull request
@tommyxchow tommyxchow merged commit 08d476d into main Aug 5, 2022
@tommyxchow tommyxchow deleted the 169-many-blocked-users branch August 5, 2022 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix A fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Frosty doesn't register that I've signed into my Twitch account.
1 participant