mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-25 08:35:16 +08:00
[client-sync] Split Contact ranking query
Summary: We were using a join for the contact ranking query and for whatever reason on large databases this was extremely slow in SQLite. This diff splits the query into first finding the sent Folder/Label and then searching for non-draft Messages in that category. Test Plan: Run locally, verify the query is faster Reviewers: juan, evan, spang Reviewed By: spang Differential Revision: https://phab.nylas.com/D4315
This commit is contained in:
parent
c4763d4bd5
commit
70bb602246
1 changed files with 12 additions and 8 deletions
|
@ -107,16 +107,20 @@ module.exports = (server) => {
|
|||
|
||||
const useLabels = account.provider === 'gmail';
|
||||
|
||||
while (true) {
|
||||
const include = [{
|
||||
model: (useLabels ? Label : Folder),
|
||||
attributes: ['id', 'role'],
|
||||
where: {role: 'sent'}},
|
||||
];
|
||||
const model = (useLabels ? Label : Folder);
|
||||
const category = await model.findOne({
|
||||
attributes: ['id', 'role'],
|
||||
where: {role: 'sent'},
|
||||
});
|
||||
|
||||
const messages = await Message.findAll({
|
||||
if (!category) {
|
||||
reply('[]');
|
||||
return;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const messages = await category.getMessages({
|
||||
attributes: ['rowid', 'id', 'to', 'cc', 'bcc', 'date'],
|
||||
include,
|
||||
where: {
|
||||
'isDraft': false, // Don't include unsent things.
|
||||
'$message.rowid$': {$gt: lastID},
|
||||
|
|
Loading…
Reference in a new issue