From 348005262b0ffde80b26b4ba876a70d825298362 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 10 Jan 2021 17:32:14 +0100 Subject: [PATCH] Classifier: cleanup msgids --- .../eu/faircode/email/MessageClassifier.java | 25 +++++++++++++++++++ .../java/eu/faircode/email/WorkerCleanup.java | 2 ++ 2 files changed, 27 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/MessageClassifier.java b/app/src/main/java/eu/faircode/email/MessageClassifier.java index ec9e28aa03..5186a1e1e5 100644 --- a/app/src/main/java/eu/faircode/email/MessageClassifier.java +++ b/app/src/main/java/eu/faircode/email/MessageClassifier.java @@ -396,6 +396,31 @@ public class MessageClassifier { Log.i("Classifier data loaded"); } + static synchronized void cleanup(@NonNull Context context) { + try { + load(context); + + DB db = DB.getInstance(context); + for (Long account : accountMsgIds.keySet()) { + List msgids = accountMsgIds.get(account); + Log.i("Classifier cleanup account=" + account + " count=" + msgids.size()); + for (String msgid : new ArrayList<>(msgids)) { + List messages = db.message().getMessagesByMsgId(account, msgid); + if (messages != null && messages.size() == 0) { + Log.i("Classifier removing msgid=" + msgid); + msgids.remove(msgid); + dirty = true; + } + } + } + + if (dirty) + save(context); + } catch (Throwable ex) { + Log.e(ex); + } + } + static synchronized void clear(@NonNull Context context) { wordClassFrequency.clear(); dirty = true; diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index a612f5b8ec..2f12968403 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -142,6 +142,8 @@ public class WorkerCleanup extends Worker { ServiceSynchronize.reschedule(context); + MessageClassifier.cleanup(context); + // Contact info cache ContactInfo.clearCache(context);