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:
parent
d2c57921b8
commit
08d476d11e
2 changed files with 10 additions and 1 deletions
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue