1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-30 19:56:10 +00:00

Improved folder query

This commit is contained in:
M66B 2019-06-26 22:08:40 +02:00
parent e981120b96
commit 9b1514e2f0

View file

@ -33,14 +33,16 @@ public interface DaoFolder {
@Query("SELECT folder.*" +
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", (SELECT COUNT(rule.id) FROM rule WHERE rule.folder = folder.id AND rule.enabled) AS rules" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
", COUNT(DISTINCT rule.id) rules" +
", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN message.ui_seen = 0 THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT operation.id) AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" LEFT JOIN rule ON rule.folder = folder.id AND rule.enabled" +
" LEFT JOIN operation ON operation.folder = folder.id AND operation.state = 'executing'" +
" WHERE folder.account = :account AND account.synchronize" +
" GROUP BY folder.id")
List<TupleFolderEx> getFoldersEx(long account);
@ -66,14 +68,16 @@ public interface DaoFolder {
@Query("SELECT folder.*" +
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", (SELECT COUNT(rule.id) FROM rule WHERE rule.folder = folder.id AND rule.enabled) AS rules" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
", COUNT(DISTINCT rule.id) rules" +
", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN message.ui_seen = 0 THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT operation.id) AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" LEFT JOIN rule ON rule.folder = folder.id AND rule.enabled" +
" LEFT JOIN operation ON operation.folder = folder.id AND operation.state = 'executing'" +
" WHERE CASE WHEN :account IS NULL" +
" THEN folder.unified AND account.synchronize" +
" ELSE folder.account = :account AND account.synchronize" +
@ -83,14 +87,16 @@ public interface DaoFolder {
@Query("SELECT folder.*" +
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", (SELECT COUNT(rule.id) FROM rule WHERE rule.folder = folder.id AND rule.enabled) AS rules" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
", COUNT(DISTINCT rule.id) rules" +
", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN message.ui_seen = 0 THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT operation.id) AS executing" +
" FROM folder" +
" JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" LEFT JOIN rule ON rule.folder = folder.id AND rule.enabled" +
" LEFT JOIN operation ON operation.folder = folder.id AND operation.state = 'executing'" +
" WHERE account.`synchronize`" +
" AND folder.unified" +
" GROUP BY folder.id")
@ -123,14 +129,16 @@ public interface DaoFolder {
@Query("SELECT folder.*" +
", account.id AS accountId, account.`order` AS accountOrder, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", (SELECT COUNT(rule.id) FROM rule WHERE rule.folder = folder.id AND rule.enabled) AS rules" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
", (SELECT COUNT(operation.id) FROM operation WHERE operation.folder = folder.id AND operation.state = 'executing') AS executing" +
", COUNT(DISTINCT rule.id) rules" +
", COUNT(DISTINCT message.id) AS messages" +
", COUNT(DISTINCT CASE WHEN message.content = 1 THEN message.id ELSE NULL END) AS content" +
", COUNT(DISTINCT CASE WHEN message.ui_seen = 0 THEN message.id ELSE NULL END) AS unseen" +
", COUNT(DISTINCT operation.id) AS executing" +
" FROM folder" +
" LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND message.ui_hide = 0" +
" LEFT JOIN rule ON rule.folder = folder.id AND rule.enabled" +
" LEFT JOIN operation ON operation.folder = folder.id AND operation.state = 'executing'" +
" WHERE folder.id = :id" +
" GROUP BY folder.id")
LiveData<TupleFolderEx> liveFolderEx(long id);