From 46341ea4582553dab62299a0bb6686c0effb8673 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 2 May 2020 08:17:20 +0200 Subject: [PATCH] Optimize query for found messages --- app/src/main/java/eu/faircode/email/DaoMessage.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 5965cdae47..9f22704f61 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -78,10 +78,9 @@ public interface DaoMessage { " AND message.thread IN" + " (SELECT DISTINCT mm.thread FROM folder ff" + " JOIN message mm ON mm.folder = ff.id" + - " WHERE (:found" + - " OR (:type IS NULL AND ff.unified)" + - " OR (:type IS NOT NULL AND ff.type = :type))" + - " AND (NOT mm.ui_hide OR :debug))" + + " WHERE ((:type IS NULL AND ff.unified) OR (:type IS NOT NULL AND ff.type = :type))" + + " AND (NOT mm.ui_hide OR :debug)" + + " AND (NOT :found OR mm.ui_found))" + " GROUP BY account.id, CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" + @@ -142,7 +141,8 @@ public interface DaoMessage { " AND message.thread IN" + " (SELECT DISTINCT mm.thread FROM message mm" + " WHERE mm.folder = :folder" + - " AND (NOT mm.ui_hide OR :debug))" + + " AND (NOT mm.ui_hide OR :debug)" + + " AND (NOT :found OR mm.ui_found))" + " GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" + " HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" + " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" +