Add compact strategy to save on disk space

This commit is contained in:
zontreck 2023-11-04 16:58:58 -07:00
parent 4fb06c8462
commit a33ebe3ffd

View file

@ -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<Box<E>> Open<E>() {
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();
}
}