Analyze before vacuum

This commit is contained in:
M66B 2020-11-30 19:10:03 +01:00
parent 358711e2dc
commit 46bf264f1c
1 changed files with 10 additions and 8 deletions

View File

@ -292,6 +292,16 @@ public class WorkerCleanup extends Worker {
int logs = db.log().deleteLogs(now - KEEP_LOG_DURATION);
Log.i("Deleted logs=" + logs);
if (BuildConfig.DEBUG) {
// https://sqlite.org/lang_analyze.html
Log.i("Analyze");
long start = new Date().getTime();
try (Cursor cursor = db.getOpenHelper().getWritableDatabase().query("PRAGMA analysis_limit=1000; PRAGMA optimize;")) {
cursor.moveToNext();
}
EntityLog.log(context, "Analyze=" + (new Date().getTime() - start) + " ms");
}
if (manual) {
// https://www.sqlite.org/lang_vacuum.html
long size = context.getDatabasePath(db.getOpenHelper().getDatabaseName()).length();
@ -306,14 +316,6 @@ public class WorkerCleanup extends Worker {
" size=" + Helper.humanReadableByteCount(size) +
"/" + Helper.humanReadableByteCount(available));
}
if (BuildConfig.DEBUG) {
// https://sqlite.org/lang_analyze.html
Log.i("Analyze");
try (Cursor cursor = db.getOpenHelper().getWritableDatabase().query("PRAGMA analysis_limit=1000; PRAGMA optimize;")) {
cursor.moveToNext();
}
}
} catch (Throwable ex) {
Log.e(ex);
} finally {