From e52b52b2baa8908621a22a6540a95f00d7b34014 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 22 May 2019 09:33:25 +0200 Subject: [PATCH] Serialize sync on init --- app/src/main/java/eu/faircode/email/Core.java | 4 +++- .../eu/faircode/email/ServiceSynchronize.java | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index e5bb6e1241..fdc49ba1ff 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1188,8 +1188,10 @@ class Core { } } - if (state.running) + if (state.running) { + folder.initialize = false; db.folder().setFolderInitialized(folder.id); + } db.folder().setFolderSync(folder.id, new Date().getTime()); db.folder().setFolderError(folder.id, null); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index e6e220b54c..c83160c2da 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -96,6 +96,7 @@ public class ServiceSynchronize extends LifecycleService { private long lastLost = 0; private TupleAccountStats lastStats = new TupleAccountStats(); private ExecutorService queue = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); + private ExecutorService initExecutor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); private static boolean booted = false; private static boolean oneshot = false; @@ -931,8 +932,18 @@ public class ServiceSynchronize extends LifecycleService { handling = ops; if (handling.size() > 0 && process) { - Log.i(folder.name + " operations=" + operations.size()); - (folder.poll ? pollExecutor : folderExecutor).submit(new Runnable() { + Log.i(folder.name + " operations=" + operations.size() + + " init=" + folder.initialize + " poll=" + folder.poll); + + ExecutorService executor; + if (folder.initialize) + executor = initExecutor; + else if (folder.poll) + executor = pollExecutor; + else + executor = folderExecutor; + + executor.submit(new Runnable() { @Override public void run() { try {