From 9088dc1f5beefe0ff2705b8091734b39e79079e5 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 3 Mar 2020 19:25:42 +0100 Subject: [PATCH] Cancel transient sync operations --- .../java/eu/faircode/email/DaoOperation.java | 3 +++ .../eu/faircode/email/ServiceSynchronize.java | 16 +++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index f02dd43f28..9936a2c3a5 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -139,4 +139,7 @@ public interface DaoOperation { @Query("DELETE FROM operation WHERE id = :id") int deleteOperation(long id); + + @Query("DELETE FROM operation WHERE account = :account AND name = :name") + int deleteOperations(long account, String name); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index ba3a4f9e78..2c4b6195b4 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1529,19 +1529,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences Log.w(account.name + " backoff " + ex.toString()); } } else { - // Stop retrying when on manual sync - if (account.ondemand) - break; - - // Stop retrying when executing operations only + // Cancel transient sync operations boolean enabled = prefs.getBoolean("enabled", true); - if (!enabled) - break; - - // Stop retrying when polling int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL); - if (pollInterval > 0 && !account.poll_exempted) - break; + if (!enabled || account.ondemand || (pollInterval > 0 && !account.poll_exempted)) { + int syncs = db.operation().deleteOperations(account.id, EntityOperation.SYNC); + Log.i(account.name + " cancelled syncs=" + syncs); + } // Long back-off period, let device sleep Intent intent = new Intent(ServiceSynchronize.this, ServiceSynchronize.class);