mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-02 09:24:45 +08:00
fix(db): Counts no longer require Thread table join
This commit is contained in:
parent
07861f64be
commit
5220b471e3
2 changed files with 8 additions and 10 deletions
|
@ -29,7 +29,7 @@ class InitialSyncActivity extends React.Component
|
||||||
incomplete = 0
|
incomplete = 0
|
||||||
|
|
||||||
for acctId, state of @state.sync
|
for acctId, state of @state.sync
|
||||||
for modelName of NylasSyncStatusStore.ModelsForSync
|
for modelName in NylasSyncStatusStore.ModelsForSync
|
||||||
modelState = state[modelName]
|
modelState = state[modelName]
|
||||||
continue unless modelState
|
continue unless modelState
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,11 @@ SetCountsQuery = ->
|
||||||
REPLACE INTO `ThreadCounts` (category_id, unread, total)
|
REPLACE INTO `ThreadCounts` (category_id, unread, total)
|
||||||
SELECT
|
SELECT
|
||||||
`ThreadCategory`.`value` as category_id,
|
`ThreadCategory`.`value` as category_id,
|
||||||
SUM(unread) as unread,
|
SUM(`ThreadCategory`.`unread`) as unread,
|
||||||
COUNT(*) as total
|
COUNT(*) as total
|
||||||
FROM `Thread`
|
FROM `ThreadCategory`
|
||||||
INNER JOIN `ThreadCategory` ON `Thread`.`id` = `ThreadCategory`.`id`
|
|
||||||
WHERE
|
WHERE
|
||||||
`Thread`.in_all_mail = 1
|
`ThreadCategory`.in_all_mail = 1
|
||||||
GROUP BY `ThreadCategory`.`value`;
|
GROUP BY `ThreadCategory`.`value`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -35,13 +34,12 @@ UpdateCountsQuery = (objectIds, operator) ->
|
||||||
REPLACE INTO `ThreadCounts` (category_id, unread, total)
|
REPLACE INTO `ThreadCounts` (category_id, unread, total)
|
||||||
SELECT
|
SELECT
|
||||||
`ThreadCategory`.`value` as category_id,
|
`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
|
COALESCE((SELECT total FROM `ThreadCounts` WHERE category_id = `ThreadCategory`.`value`), 0) #{operator} COUNT(*) as total
|
||||||
FROM `Thread`
|
FROM `ThreadCategory`
|
||||||
INNER JOIN `ThreadCategory` ON `Thread`.`id` = `ThreadCategory`.`id`
|
|
||||||
WHERE
|
WHERE
|
||||||
`Thread`.id IN (#{objectIdsString}) AND
|
`ThreadCategory`.id IN (#{objectIdsString}) AND
|
||||||
`Thread`.in_all_mail = 1
|
`ThreadCategory`.in_all_mail = 1
|
||||||
GROUP BY `ThreadCategory`.`value`
|
GROUP BY `ThreadCategory`.`value`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue