Fix large blocked users list preventing login (#175)

* Remove await from get blocked users

* Implement request limit to blocked users
This commit is contained in:
Tommy Chow 2022-08-05 03:24:35 -04:00 • committed by GitHub
parent d2c57921b8
commit 08d476d11e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -410,6 +410,12 @@ class TwitchApi {
final result = blockedList.map((e) => UserBlockedTwitch.fromJson(e)).toList();
if (cursor != null) {
// Wait a bit (150 milliseconds) before recursively calling.
// This will prevent going over the rate limit to due a massive blocked users list.
//
// With the Twitch API, we can make up to 800 requests per minute.
// Waiting 150 milliseconds between requests will cap the rate here at 400 requests per minute.
await Future.delayed(const Duration(milliseconds: 150));
result.addAll(await getUserBlockedList(id: id, cursor: cursor, headers: headers));
}

View file

@ -27,7 +27,10 @@ abstract class UserStoreBase with Store {
_details = await twitchApi.getUserInfo(headers: headers);
// Get and update the current user's list of blocked users.
if (_details?.id != null) _blockedUsers = (await twitchApi.getUserBlockedList(id: _details!.id, headers: headers)).asObservable();
// Don't use await because having a huge list of blocked users will block the UI.
if (_details?.id != null) {
twitchApi.getUserBlockedList(id: _details!.id, headers: headers).then((blockedUsers) => _blockedUsers = blockedUsers.asObservable());
}
_disposeReaction = autorun((_) => _blockedUsers.sort((a, b) => a.userLogin.compareTo(b.userLogin)));
}