From 5220b471e3ec3134a128f98a2259247c5b87aff1 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 11 Apr 2016 13:51:31 -0700 Subject: [PATCH] fix(db): Counts no longer require Thread table join --- .../lib/sidebar/initial-sync-activity.cjsx | 2 +- src/flux/stores/thread-counts-store.coffee | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal_packages/notifications/lib/sidebar/initial-sync-activity.cjsx b/internal_packages/notifications/lib/sidebar/initial-sync-activity.cjsx index 3c81f49c2..df63a2aba 100644 --- a/internal_packages/notifications/lib/sidebar/initial-sync-activity.cjsx +++ b/internal_packages/notifications/lib/sidebar/initial-sync-activity.cjsx @@ -29,7 +29,7 @@ class InitialSyncActivity extends React.Component incomplete = 0 for acctId, state of @state.sync - for modelName of NylasSyncStatusStore.ModelsForSync + for modelName in NylasSyncStatusStore.ModelsForSync modelState = state[modelName] continue unless modelState diff --git a/src/flux/stores/thread-counts-store.coffee b/src/flux/stores/thread-counts-store.coffee index 70908fa6b..633f61b3c 100644 --- a/src/flux/stores/thread-counts-store.coffee +++ b/src/flux/stores/thread-counts-store.coffee @@ -20,12 +20,11 @@ SetCountsQuery = -> REPLACE INTO `ThreadCounts` (category_id, unread, total) SELECT `ThreadCategory`.`value` as category_id, - SUM(unread) as unread, + SUM(`ThreadCategory`.`unread`) as unread, COUNT(*) as total - FROM `Thread` - INNER JOIN `ThreadCategory` ON `Thread`.`id` = `ThreadCategory`.`id` + FROM `ThreadCategory` WHERE - `Thread`.in_all_mail = 1 + `ThreadCategory`.in_all_mail = 1 GROUP BY `ThreadCategory`.`value`; """ @@ -35,13 +34,12 @@ UpdateCountsQuery = (objectIds, operator) -> REPLACE INTO `ThreadCounts` (category_id, unread, total) SELECT `ThreadCategory`.`value` as category_id, - COALESCE((SELECT unread FROM `ThreadCounts` WHERE category_id = `ThreadCategory`.`value`), 0) #{operator} SUM(unread) as unread, + COALESCE((SELECT unread FROM `ThreadCounts` WHERE category_id = `ThreadCategory`.`value`), 0) #{operator} SUM(`ThreadCategory`.`unread`) as unread, COALESCE((SELECT total FROM `ThreadCounts` WHERE category_id = `ThreadCategory`.`value`), 0) #{operator} COUNT(*) as total - FROM `Thread` - INNER JOIN `ThreadCategory` ON `Thread`.`id` = `ThreadCategory`.`id` + FROM `ThreadCategory` WHERE - `Thread`.id IN (#{objectIdsString}) AND - `Thread`.in_all_mail = 1 + `ThreadCategory`.id IN (#{objectIdsString}) AND + `ThreadCategory`.in_all_mail = 1 GROUP BY `ThreadCategory`.`value` """