diff --git a/src/flux/models/query.coffee b/src/flux/models/query.coffee index 12507e0c7..bc0cbeb39 100644 --- a/src/flux/models/query.coffee +++ b/src/flux/models/query.coffee @@ -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 diff --git a/src/flux/models/thread.es6 b/src/flux/models/thread.es6 index 82f6e42c6..a8ca47410 100644 --- a/src/flux/models/thread.es6 +++ b/src/flux/models/thread.es6 @@ -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)', ], }