[client-sync] limit attributes returned for messages

Summary:
I did a grep for `Message.find.*` to see if there were any other places
we could limit the attributes returned

There were.

This used to be INSANELY wasteful to return all bodies when we only needed
the ids.

Test Plan: Manually bootup app and ensure search still works

Reviewers: mark, juan, spang

Reviewed By: mark, juan, spang

Differential Revision: https://phab.nylas.com/D4042
This commit is contained in:
Evan Morikawa 2017-02-24 11:04:18 -08:00
parent c7bdb5804a
commit f23a96c481
2 changed files with 6 additions and 1 deletions

View file

@ -147,6 +147,7 @@ class GmailSearchClient {
const {Message} = db;
const messages = await Message.findAll({
attributes: ['id', 'threadId'],
where: {gMsgId: {$in: messageIds}},
});
@ -250,6 +251,7 @@ class ImapSearchClient {
const {Message} = db;
return (await this._search(db, query)).flatMap((uids) => {
return Message.findAll({
attributes: ['id', 'threadId'],
where: {folderImapUID: uids},
});
}).flatMap((messages) => {

View file

@ -103,7 +103,10 @@ class SyncbackTaskRunner {
affectedMessageIds.add(messageId)
}
} else if (threadId) {
const messageIds = await Message.findAll({where: {threadId}}).map(m => m.id)
const messageIds = await Message.findAll({
attributes: ['id', 'threadId'],
where: {threadId}})
.map(m => m.id)
const shouldIncludeTask = messageIds.every(id => !affectedMessageIds.has(id))
if (shouldIncludeTask) {
tasksToProcess.push(task)