From ded0068ea6b457ff9a18b8fe061923fdbc7ae87c Mon Sep 17 00:00:00 2001 From: nyne Date: Thu, 22 May 2025 20:37:25 +0800 Subject: [PATCH] Improve performance for clearing history. --- lib/foundation/history.dart | 13 ++++++++++--- lib/pages/history_page.dart | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/foundation/history.dart b/lib/foundation/history.dart index 412e0f5..3a1ae65 100644 --- a/lib/foundation/history.dart +++ b/lib/foundation/history.dart @@ -306,7 +306,9 @@ class HistoryManager with ChangeNotifier { notifyListeners(); } - void clearUnfavoritedHistory() { +void clearUnfavoritedHistory() { + _db.execute('BEGIN TRANSACTION;'); + try { final idAndTypes = _db.select(""" select id, type from history; """); @@ -320,9 +322,14 @@ class HistoryManager with ChangeNotifier { """, [id, type.value]); } } - updateCache(); - notifyListeners(); + _db.execute('COMMIT;'); + } catch (e) { + _db.execute('ROLLBACK;'); + rethrow; } + updateCache(); + notifyListeners(); +} void remove(String id, ComicType type) async { _db.execute(""" diff --git a/lib/pages/history_page.dart b/lib/pages/history_page.dart index 9a631cf..bd65ce7 100644 --- a/lib/pages/history_page.dart +++ b/lib/pages/history_page.dart @@ -147,6 +147,7 @@ class _HistoryPageState extends State { }, child: Text('Clear Unfavorited'.tl), ), + const SizedBox(width: 4), Button.filled( color: context.colorScheme.error, onPressed: () {