From 3ed182530dc5b98ab79d1f35fea83848f9d8ccc5 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 22 Jan 2020 21:39:38 +0100 Subject: [PATCH] Skip polling of on demand accounts --- .../main/java/eu/faircode/email/DaoAccount.java | 7 +++++++ .../main/java/eu/faircode/email/ServiceUI.java | 17 ++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoAccount.java b/app/src/main/java/eu/faircode/email/DaoAccount.java index f558c96ac4..11088c4966 100644 --- a/app/src/main/java/eu/faircode/email/DaoAccount.java +++ b/app/src/main/java/eu/faircode/email/DaoAccount.java @@ -37,6 +37,13 @@ public interface DaoAccount { " ORDER BY `order`, `primary` DESC, name COLLATE NOCASE") List getSynchronizingAccounts(); + @Query("SELECT * FROM account" + + " WHERE (:id IS NULL OR id = :id)" + + " AND synchronize" + + " AND NOT ondemand" + + " ORDER BY `order`, `primary` DESC, name COLLATE NOCASE") + List getPollAccounts(Long id); + @Query("SELECT * FROM account WHERE synchronize") LiveData> liveSynchronizingAccounts(); diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index ab03e5e99c..a57c84e48b 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -445,15 +445,14 @@ public class ServiceUI extends IntentService { try { db.beginTransaction(); - List accounts = db.account().getSynchronizingAccounts(); - for (EntityAccount account : accounts) - if (aid < 0 || account.id.equals(aid)) { - List folders = db.folder().getSynchronizingFolders(account.id); - if (folders.size() > 0) - Collections.sort(folders, folders.get(0).getComparator(this)); - for (EntityFolder folder : folders) - EntityOperation.sync(this, folder.id, false); - } + List accounts = db.account().getPollAccounts(aid < 0 ? null : aid); + for (EntityAccount account : accounts) { + List folders = db.folder().getSynchronizingFolders(account.id); + if (folders.size() > 0) + Collections.sort(folders, folders.get(0).getComparator(this)); + for (EntityFolder folder : folders) + EntityOperation.sync(this, folder.id, false); + } db.setTransactionSuccessful(); } finally {