fix(db): Counts no longer require Thread table join

This commit is contained in:
Ben Gotow 2016-04-11 13:51:31 -07:00
parent b75ed6f920
commit f7bfb2aceb
2 changed files with 8 additions and 10 deletions

View file

@ -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

View file

@ -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`
"""