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() .and()
.isMangaEqualTo(_tabBarController.index == 0) .isMangaEqualTo(_tabBarController.index == 0)
.findAllSync(); .findAllSync();
int numbers = 0;
try {
for (var manga in mangaList) { await Future.wait(
try { mangaList.map((manga) async {
await ref.read( try {
updateMangaDetailProvider(mangaId: manga.id, isInit: false).future); await ref.read(
} catch (_) {} updateMangaDetailProvider(mangaId: manga.id, isInit: false).future,
numbers++; );
} 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 @override