perf(db): Use same subselect for "related emails" queries

This commit is contained in:
Ben Gotow 2016-04-12 09:50:03 -07:00
parent 7b03a80d02
commit 436107844d
2 changed files with 8 additions and 2 deletions

View file

@ -289,7 +289,8 @@ class ModelQuery
#
_canSubselectForJoin: (matcher) ->
joinAttribute = matcher.attribute()
return false unless joinAttribute.joinOnField is 'id'
return unless @_range.limit?
allMatchersOnJoinTable = _.every @_matchers, (m) ->
m is matcher or joinAttribute.joinQueryableBy.indexOf(m.attr.modelKey) isnt -1

View file

@ -80,6 +80,7 @@ class Thread extends ModelWithMetadata {
queryable: true,
joinOnField: 'email',
modelKey: 'participants',
joinQueryableBy: ['lastMessageReceivedTimestamp'],
itemClass: Contact,
}),
@ -115,9 +116,13 @@ class Thread extends ModelWithMetadata {
'CREATE TABLE IF NOT EXISTS `ThreadCounts` (`category_id` TEXT PRIMARY KEY, `unread` INTEGER, `total` INTEGER)',
'CREATE UNIQUE INDEX IF NOT EXISTS ThreadCountsIndex ON `ThreadCounts` (category_id DESC)',
'CREATE INDEX IF NOT EXISTS ThreadContactDateIndex ON `ThreadContact`(last_message_received_timestamp DESC, value, id)',
'CREATE INDEX IF NOT EXISTS ThreadDateIndex ON `Thread`(last_message_received_timestamp DESC, id)',
'CREATE INDEX IF NOT EXISTS ThreadStarIndex ON Thread(account_id, starred)',
'CREATE INDEX IF NOT EXISTS ThreadListCategoryIndex ON `ThreadCategory`(last_message_received_timestamp DESC, value, in_all_mail, unread, id)',
'CREATE INDEX IF NOT EXISTS ThreadListCategorySentIndex ON `ThreadCategory`(last_message_sent_timestamp DESC, value, in_all_mail, unread, id)',
'CREATE INDEX IF NOT EXISTS ThreadStarIndex ON Thread(account_id, starred)',
],
}