From 1982c72f03ac7bb1fc6c30ddfb977407098c437d Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 17 Sep 2019 16:36:19 +0200 Subject: [PATCH] Skip redundant operations --- app/src/main/java/eu/faircode/email/Core.java | 27 ++++++++++++++++--- .../eu/faircode/email/EntityOperation.java | 15 ----------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 6650a7ae18..664f22deb9 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -177,11 +177,32 @@ class Core { // Operations should use database transaction when needed - // Squash operations - if (i + 1 < ops.size() && op.canSquash(ops.get(i + 1))) { + // Skip redundant operations + boolean skip = false; + for (int j = i + 1; j < ops.size(); j++) { + EntityOperation next = ops.get(j); + + if (EntityOperation.ADD.equals(op.name)) { + if (Objects.equals(op.message, next.message) && + (EntityOperation.ADD.equals(next.name) || + EntityOperation.DELETE.equals(next.name))) { + skip = true; + break; + } + } else if (EntityOperation.FETCH.equals(op.name)) + if (EntityOperation.FETCH.equals(next.name)) { + JSONArray jnext = new JSONArray(next.args); + if (jargs.getLong(0) == jnext.getLong(0)) { + skip = true; + break; + } + } + } + if (skip) { Log.i(folder.name + - " squashing op=" + op.id + "/" + op.name + + " skipping op=" + op.id + "/" + op.name + " msg=" + op.message + " args=" + op.args); + db.operation().deleteOperation(op.id); continue; } diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 3cf2082735..f88127eda6 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -341,21 +341,6 @@ public class EntityOperation { Log.i("Queued subscribe=" + subscribe + " folder=" + folder); } - boolean canSquash(EntityOperation next) throws JSONException { - if (Objects.equals(this.message, next.message) && - ADD.equals(this.name) && - (ADD.equals(next.name) || DELETE.equals(next.name))) - return true; - - if (FETCH.equals(this.name) && FETCH.equals(next.name)) { - JSONArray jargs1 = new JSONArray(this.args); - JSONArray jargs2 = new JSONArray(next.args); - return (jargs1.optLong(0, -1) == jargs2.optLong(0, -2)); - } - - return false; - } - @Override public boolean equals(Object obj) { if (obj instanceof EntityOperation) {