From 1dc1b0ae6f5bb0d12126c39f7dc990e187b3301e Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 9 Nov 2020 21:29:14 +0100 Subject: [PATCH] Really limit fetch --- .../eu/faircode/email/EntityOperation.java | 56 ++++++------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 5b50f196af..bc62a16d26 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -321,13 +321,6 @@ public class EntityOperation { } return; - } else if (FETCH.equals(name)) { - int count = db.operation().getOperationCount(message.folder, name); - if (count >= MAX_FETCH) { - sync(context, message.folder, false); - return; - } - } else if (DELETE.equals(name)) { db.message().setMessageUiHide(message.id, true); /* @@ -349,9 +342,26 @@ public class EntityOperation { } } - private static void queue(Context context, Long account, long folder, long message, String name, JSONArray jargs) { + static void queue(Context context, EntityFolder folder, String name, Object... values) { + JSONArray jargs = new JSONArray(); + for (Object value : values) + jargs.put(value); + + queue(context, folder.account, folder.id, null, name, jargs); + } + + private static void queue(Context context, Long account, long folder, Long message, String name, JSONArray jargs) { DB db = DB.getInstance(context); + if (FETCH.equals(name)) { + int count = db.operation().getOperationCount(folder, name); + if (count >= MAX_FETCH) { + Log.i("Replacing fetch by sync folder=" + folder + " args=" + jargs + " count=" + count); + sync(context, folder, false); + return; + } + } + EntityOperation op = new EntityOperation(); op.account = account; op.folder = folder; @@ -375,36 +385,6 @@ public class EntityOperation { Log.breadcrumb("queued", crumb); } - static void queue(Context context, EntityFolder folder, String name, Object... values) { - DB db = DB.getInstance(context); - - JSONArray jargs = new JSONArray(); - for (Object value : values) - jargs.put(value); - - EntityOperation op = new EntityOperation(); - op.account = folder.account; - op.folder = folder.id; - op.message = null; - op.name = name; - op.args = jargs.toString(); - op.created = new Date().getTime(); - op.id = db.operation().insertOperation(op); - - Log.i("Queued op=" + op.id + "/" + op.name + - " folder=" + op.folder + " msg=" + op.message + - " args=" + op.args); - - Map crumb = new HashMap<>(); - crumb.put("name", op.name); - crumb.put("args", op.args); - crumb.put("folder", op.account + ":" + op.folder); - if (op.message != null) - crumb.put("message", Long.toString(op.message)); - crumb.put("free", Integer.toString(Log.getFreeMemMb())); - Log.breadcrumb("queued", crumb); - } - static void sync(Context context, long fid, boolean foreground) { DB db = DB.getInstance(context);