From 60848a43bf90f9afb208dafdd399d934af985f1b Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 5 Oct 2019 17:47:56 +0200 Subject: [PATCH] Prioritize body/attachments operations --- .../java/eu/faircode/email/DaoOperation.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index 0ba9454272..720a019224 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -28,6 +28,14 @@ import java.util.List; @Dao public interface DaoOperation { + String priority = "CASE" + + " WHEN operation.name = '" + EntityOperation.BODY + "' THEN -2" + + " WHEN operation.name = '" + EntityOperation.ATTACHMENT + "' THEN -1" + + " WHEN operation.name = '" + EntityOperation.SYNC + "' THEN" + + " CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox + " ELSE 0" + + " END"; + @Query("SELECT operation.*, account.name AS accountName, folder.name AS folderName" + " ,((account.synchronize IS NULL OR account.synchronize)" + " AND (NOT folder.account IS NULL OR identity.synchronize IS NULL OR identity.synchronize)) AS synchronize" + @@ -36,12 +44,7 @@ public interface DaoOperation { " LEFT JOIN message ON message.id = operation.message" + " LEFT JOIN account ON account.id = operation.account OR account.id = folder.account" + " LEFT JOIN identity ON identity.id = message.identity" + - " ORDER BY" + - " CASE WHEN operation.name = '" + EntityOperation.SYNC + "' THEN" + - " CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox - " ELSE 0" + - " END" + - ", id") + " ORDER BY " + priority + ", id") LiveData> liveOperations(); String GET_OPS_FOLDER = "SELECT operation.* FROM operation" + @@ -52,12 +55,7 @@ public interface DaoOperation { " WHERE CASE WHEN :folder IS NULL THEN folder.account IS NULL ELSE operation.folder = :folder END" + " AND (account.synchronize IS NULL OR account.synchronize)" + " AND (NOT folder.account IS NULL OR identity.synchronize IS NULL OR identity.synchronize)" + - " ORDER BY" + - " CASE WHEN operation.name = '" + EntityOperation.SYNC + "' THEN" + - " CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox - " ELSE 0" + - " END" + - ", id"; + " ORDER BY " + priority + ", id"; @Query(GET_OPS_FOLDER) List getOperations(Long folder);