Cleanup worker logging

pull/214/head
M66B 2 years ago
parent 66d00d710e
commit 3f31ed7286

@ -104,9 +104,12 @@ public class WorkerCleanup extends Worker {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
semaphore.acquire(); semaphore.acquire();
Log.breadcrumb("worker", "cleanup", "start");
EntityLog.log(context, "Start cleanup manual=" + manual); EntityLog.log(context, "Start cleanup manual=" + manual);
if (manual) { if (manual) {
Log.breadcrumb("worker", "cleanup", "manual");
// Check message files // Check message files
Log.i("Checking message files"); Log.i("Checking message files");
try (Cursor cursor = db.message().getMessageWithContent()) { try (Cursor cursor = db.message().getMessageWithContent()) {
@ -207,7 +210,7 @@ public class WorkerCleanup extends Worker {
long now = new Date().getTime(); long now = new Date().getTime();
// Cleanup message files // Cleanup message files
Log.i("Cleanup message files"); Log.breadcrumb("worker", "cleanup", "message files");
cleanupMessageFiles(db, manual, Helper.listFiles(new File(context.getFilesDir(), "messages")).toArray(new File[0])); cleanupMessageFiles(db, manual, Helper.listFiles(new File(context.getFilesDir(), "messages")).toArray(new File[0]));
cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "revision").listFiles()); cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "revision").listFiles());
cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "references").listFiles()); cleanupMessageFiles(db, manual, new File(context.getFilesDir(), "references").listFiles());
@ -217,7 +220,7 @@ public class WorkerCleanup extends Worker {
// Cleanup raw message files // Cleanup raw message files
if (!download_eml) { if (!download_eml) {
Log.i("Cleanup raw message files"); Log.breadcrumb("worker", "cleanup", "raw message files");
File[] raws = new File(context.getFilesDir(), "raw").listFiles(); File[] raws = new File(context.getFilesDir(), "raw").listFiles();
if (raws != null) if (raws != null)
for (File file : raws) for (File file : raws)
@ -243,8 +246,8 @@ public class WorkerCleanup extends Worker {
} }
// Cleanup attachment files // Cleanup attachment files
Log.i("Cleanup attachment files");
{ {
Log.breadcrumb("worker", "cleanup", "attachment files");
File[] attachments = new File(EntityAttachment.getRoot(context), "attachments").listFiles(); File[] attachments = new File(EntityAttachment.getRoot(context), "attachments").listFiles();
if (attachments != null) if (attachments != null)
for (File file : attachments) for (File file : attachments)
@ -263,8 +266,8 @@ public class WorkerCleanup extends Worker {
} }
// Cleanup cached images // Cleanup cached images
Log.i("Cleanup cached image files");
{ {
Log.breadcrumb("worker", "cleanup", "image files");
File[] images = new File(context.getFilesDir(), "images").listFiles(); File[] images = new File(context.getFilesDir(), "images").listFiles();
if (images != null) if (images != null)
for (File file : images) for (File file : images)
@ -285,6 +288,7 @@ public class WorkerCleanup extends Worker {
// Cleanup shared files // Cleanup shared files
{ {
Log.breadcrumb("worker", "cleanup", "shared files");
File[] shared = new File(context.getFilesDir(), "shared").listFiles(); File[] shared = new File(context.getFilesDir(), "shared").listFiles();
if (shared != null) if (shared != null)
for (File file : shared) for (File file : shared)
@ -295,6 +299,7 @@ public class WorkerCleanup extends Worker {
} }
// Cleanup contact info // Cleanup contact info
Log.breadcrumb("worker", "cleanup", "contact info");
if (manual) if (manual)
ContactInfo.clearCache(context); ContactInfo.clearCache(context);
else else
@ -302,6 +307,7 @@ public class WorkerCleanup extends Worker {
Log.i("Cleanup FTS=" + fts); Log.i("Cleanup FTS=" + fts);
if (fts) { if (fts) {
Log.breadcrumb("worker", "cleanup", "FTS");
int deleted = 0; int deleted = 0;
SQLiteDatabase sdb = Fts4DbHelper.getInstance(context); SQLiteDatabase sdb = Fts4DbHelper.getInstance(context);
try (Cursor cursor = Fts4DbHelper.getIds(sdb)) { try (Cursor cursor = Fts4DbHelper.getIds(sdb)) {
@ -320,7 +326,7 @@ public class WorkerCleanup extends Worker {
Fts4DbHelper.optimize(sdb); Fts4DbHelper.optimize(sdb);
} }
Log.i("Cleanup contacts"); Log.breadcrumb("worker", "cleanup", "contacts");
try { try {
db.beginTransaction(); db.beginTransaction();
int contacts = db.contact().countContacts(); int contacts = db.contact().countContacts();
@ -334,7 +340,7 @@ public class WorkerCleanup extends Worker {
if (sqlite_analyze) { if (sqlite_analyze) {
// https://sqlite.org/lang_analyze.html // https://sqlite.org/lang_analyze.html
Log.i("Running analyze"); Log.breadcrumb("worker", "cleanup", "analyze");
long analyze = new Date().getTime(); long analyze = new Date().getTime();
try (Cursor cursor = db.getOpenHelper().getWritableDatabase().query("PRAGMA analysis_limit=1000; PRAGMA optimize;")) { try (Cursor cursor = db.getOpenHelper().getWritableDatabase().query("PRAGMA analysis_limit=1000; PRAGMA optimize;")) {
cursor.moveToNext(); cursor.moveToNext();
@ -342,11 +348,15 @@ public class WorkerCleanup extends Worker {
EntityLog.log(context, "Analyze=" + (new Date().getTime() - analyze) + " ms"); EntityLog.log(context, "Analyze=" + (new Date().getTime() - analyze) + " ms");
} }
Log.breadcrumb("worker", "cleanup", "emergency");
DB.createEmergencyBackup(context); DB.createEmergencyBackup(context);
Log.breadcrumb("worker", "cleanup", "shortcuts");
Shortcuts.cleanup(context); Shortcuts.cleanup(context);
if (manual) { if (manual) {
Log.breadcrumb("worker", "cleanup", "vacuum");
// https://www.sqlite.org/lang_vacuum.html // https://www.sqlite.org/lang_vacuum.html
long size = context.getDatabasePath(db.getOpenHelper().getDatabaseName()).length(); long size = context.getDatabasePath(db.getOpenHelper().getDatabaseName()).length();
long available = Helper.getAvailableStorageSpace(); long available = Helper.getAvailableStorageSpace();
@ -364,6 +374,7 @@ public class WorkerCleanup extends Worker {
Log.e(ex); Log.e(ex);
} finally { } finally {
semaphore.release(); semaphore.release();
Log.breadcrumb("worker", "cleanup", "end");
EntityLog.log(context, "End cleanup=" + (new Date().getTime() - start) + " ms"); EntityLog.log(context, "End cleanup=" + (new Date().getTime() - start) + " ms");
long now = new Date().getTime(); long now = new Date().getTime();

Loading…
Cancel
Save