diff --git a/lib/services/history_database.dart b/lib/services/history_database.dart index f5c49199..cde69b50 100644 --- a/lib/services/history_database.dart +++ b/lib/services/history_database.dart @@ -796,6 +796,11 @@ class HistoryDatabase { await txn.delete('history_path_keys'); await txn.delete('history'); }); + // Return freed pages to the OS (no-op unless the file was created with + // auto_vacuum enabled). + try { + await db.execute('PRAGMA incremental_vacuum'); + } catch (_) {} _log.i('Cleared all history'); } diff --git a/lib/services/sqlite_helpers.dart b/lib/services/sqlite_helpers.dart index 829b1abf..03213d44 100644 --- a/lib/services/sqlite_helpers.dart +++ b/lib/services/sqlite_helpers.dart @@ -28,6 +28,10 @@ Future openAppDatabase( if (foreignKeys) { await db.execute('PRAGMA foreign_keys = ON'); } + // Without auto_vacuum the file never shrinks after deletes — its size + // is a permanent high-water mark. Only takes effect on newly created + // databases; existing files keep their mode until a manual VACUUM. + await db.execute('PRAGMA auto_vacuum = INCREMENTAL'); await db.rawQuery('PRAGMA journal_mode = WAL'); await db.execute('PRAGMA synchronous = NORMAL'); },