From a33ebe3ffd516457eee692702d7b9be6a8fff41f Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 4 Nov 2023 16:58:58 -0700 Subject: [PATCH] Add compact strategy to save on disk space --- lib/settings.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/settings.dart b/lib/settings.dart index df36730..e334dd3 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -27,6 +27,8 @@ class Settings { if (!isValid()) return; var box = Hive.box("settings"); box.put("entry", inst); + + box.compact(); } bool isValid() { @@ -39,12 +41,20 @@ class Settings { Future> Open() { Close(); - return Hive.openBox("settings", path: game_path); + return Hive.openBox( + "settings", + path: game_path, + compactionStrategy: (entries, deletedEntries) { + return deletedEntries > 1; + }, + ); } static void Close() { if (Hive.isBoxOpen("settings")) { - Hive.box("settings").close(); + var box = Hive.box("settings"); + box.compact(); + box.close(); } }