mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Add VACUUM to dev settings
This commit is contained in:
parent
5074498444
commit
6ca54f0776
2 changed files with 34 additions and 0 deletions
|
@ -99,6 +99,17 @@ extension SqliteDbExtension on SqliteDb {
|
|||
});
|
||||
}
|
||||
|
||||
/// Run [block] after acquiring the database
|
||||
///
|
||||
/// The [db] argument passed to [block] is identical to this
|
||||
///
|
||||
/// This function does not start a transaction, see [use] instead
|
||||
Future<T> useNoTransaction<T>(Future<T> Function(SqliteDb db) block) async {
|
||||
return await platform.Lock.synchronized(k.appDbLockId, () async {
|
||||
return await block(this);
|
||||
});
|
||||
}
|
||||
|
||||
/// Start an isolate and run [callback] there, with access to the
|
||||
/// SQLite database
|
||||
Future<U> isolate<T, U>(T args, ComputeWithDbCallback<T, U> callback) async {
|
||||
|
|
|
@ -1622,6 +1622,10 @@ class _DevSettingsState extends State<_DevSettings> {
|
|||
title: const Text("Clear cache database"),
|
||||
onTap: () => _clearCacheDb(),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text("SQL:VACUUM"),
|
||||
onTap: () => _runSqlVacuum(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1652,6 +1656,25 @@ class _DevSettingsState extends State<_DevSettings> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _runSqlVacuum() async {
|
||||
try {
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
await c.sqliteDb.useNoTransaction((db) async {
|
||||
await db.customStatement("VACUUM;");
|
||||
});
|
||||
SnackBarManager().showSnackBar(const SnackBar(
|
||||
content: Text("Finished successfully"),
|
||||
duration: k.snackBarDurationShort,
|
||||
));
|
||||
} catch (e, stackTrace) {
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(exception_util.toUserString(e)),
|
||||
duration: k.snackBarDurationNormal,
|
||||
));
|
||||
_log.shout("[_runSqlVacuum] Uncaught exception", e, stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
static final _log = Logger("widget.settings._DevSettingsState");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue