Improved performance of update in updates screen

Now in parallel instead of sequentially, 2x faster.
Benchmarked using stopwatch with 31 items in library:

Sequential:
1. 78771 ms
2. 74503 ms
3. 73165 ms

Parallel:
1. 36270 ms
2. 33703 ms
3. 33838 ms
This commit is contained in:
NBA2K1 2024-12-16 19:31:11 +01:00
parent 1b16573b06
commit da3bcf1081

View file

@ -44,26 +44,25 @@ class _UpdatesScreenState extends ConsumerState<UpdatesScreen>
.and()
.isMangaEqualTo(_tabBarController.index == 0)
.findAllSync();
int numbers = 0;
for (var manga in mangaList) {
try {
await ref.read(
updateMangaDetailProvider(mangaId: manga.id, isInit: false).future);
} catch (_) {}
numbers++;
try {
await Future.wait(
mangaList.map((manga) async {
try {
await ref.read(
updateMangaDetailProvider(mangaId: manga.id, isInit: false).future,
);
} catch (e) {
debugPrint("Failed to update manga with ID ${manga.id}: $e");
}
}),
);
} finally {
BotToast.cleanAll();
setState(() {
_isLoading = false;
});
}
await Future.doWhile(() async {
await Future.delayed(const Duration(seconds: 1));
if (mangaList.length == numbers) {
return false;
}
return true;
});
BotToast.cleanAll();
setState(() {
_isLoading = false;
});
}
@override