From f23a96c481c397232581eb315b74895369c64105 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 24 Feb 2017 11:04:18 -0800 Subject: [PATCH] [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 --- packages/client-sync/src/local-api/search.js | 2 ++ .../src/local-sync-worker/syncback-task-runner.es6 | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/client-sync/src/local-api/search.js b/packages/client-sync/src/local-api/search.js index b066a4cd8..4bb935fbd 100644 --- a/packages/client-sync/src/local-api/search.js +++ b/packages/client-sync/src/local-api/search.js @@ -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) => { diff --git a/packages/client-sync/src/local-sync-worker/syncback-task-runner.es6 b/packages/client-sync/src/local-sync-worker/syncback-task-runner.es6 index 6c316a07a..cf81bae0c 100644 --- a/packages/client-sync/src/local-sync-worker/syncback-task-runner.es6 +++ b/packages/client-sync/src/local-sync-worker/syncback-task-runner.es6 @@ -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)