From 232ae8ea86d94446271dcca37cdd3792aa098f59 Mon Sep 17 00:00:00 2001 From: Whiskas101 Date: Sun, 30 Nov 2025 13:38:49 +0530 Subject: [PATCH] change: switch to async fetch for isar due to lag in large libraries --- .../widgets/manga_image_card_widget.dart | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/modules/widgets/manga_image_card_widget.dart b/lib/modules/widgets/manga_image_card_widget.dart index fa1cca02..d166f87b 100644 --- a/lib/modules/widgets/manga_image_card_widget.dart +++ b/lib/modules/widgets/manga_image_card_widget.dart @@ -320,14 +320,14 @@ Future pushToMangaReaderDetail({ .sourceEqualTo(manga.source) .isEmptySync(); if (empty) { - isar.writeTxnSync(() { - isar.mangas.putSync( + await isar.writeTxn(() async { + await isar.mangas.put( manga..updatedAt = DateTime.now().millisecondsSinceEpoch, ); }); } else { - isar.writeTxnSync(() { - isar.mangas.putSync(manga); + await isar.writeTxn(() async { + await isar.mangas.put(manga); }); } @@ -349,8 +349,8 @@ Future pushToMangaReaderDetail({ final mang = isar.mangas.getSync(mangaId); if (mang!.sourceId == null && !(mang.isLocalArchive ?? false)) { - isar.writeTxnSync(() { - isar.mangas.putSync(mang..sourceId = sourceId); + await isar.writeTxn(() async { + await isar.mangas.put(mang..sourceId = sourceId); }); } final settings = isar.settings.getSync(227)!; @@ -359,7 +359,7 @@ Future pushToMangaReaderDetail({ .where((element) => element.mangaId == mangaId) .toList(); if (checkIfExist.isEmpty) { - isar.writeTxnSync(() { + await isar.writeTxn(() async { List? sortChapterList = []; for (var sortChapter in settings.sortChapterList ?? []) { sortChapterList.add(sortChapter); @@ -384,7 +384,7 @@ Future pushToMangaReaderDetail({ ChapterFilterDownloaded()..mangaId = mangaId, ); chapterFilterUnreadList.add(ChapterFilterUnread()..mangaId = mangaId); - isar.settings.putSync( + await isar.settings.put( settings ..sortChapterList = sortChapterList ..chapterFilterBookmarkedList = chapterFilterBookmarkedList @@ -395,22 +395,24 @@ Future pushToMangaReaderDetail({ }); } if (!addToFavourite) { - if (useMaterialRoute) { - await Navigator.push( - context, - createRoute(page: MangaReaderDetail(mangaId: mangaId)), - ); + if (context.mounted) { + if (useMaterialRoute) { + await Navigator.push( + context, + createRoute(page: MangaReaderDetail(mangaId: mangaId)), + ); + } else { + await context.push('/manga-reader/detail', extra: mangaId); + } } else { - await context.push('/manga-reader/detail', extra: mangaId); + final getManga = isar.mangas.filter().idEqualTo(mangaId).findFirstSync()!; + await isar.writeTxn(() async { + await isar.mangas.put( + getManga + ..favorite = !getManga.favorite! + ..updatedAt = DateTime.now().millisecondsSinceEpoch, + ); + }); } - } else { - final getManga = isar.mangas.filter().idEqualTo(mangaId).findFirstSync()!; - isar.writeTxnSync(() { - isar.mangas.putSync( - getManga - ..favorite = !getManga.favorite! - ..updatedAt = DateTime.now().millisecondsSinceEpoch, - ); - }); } }