From 5e35d39eb26e4540496c1ea3aa31bf4410e7fefa Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 22 Feb 2017 14:39:57 -0800 Subject: [PATCH] [client-app] Properly re-index threads when their data has changed Summary: When we detect that threads in the database have changed, if they've already been indexed, mark them as unindexed so that the indexer picks them up and re-indexes them with the updated data Test Plan: manual Reviewers: evan, spang, mark Reviewed By: mark Differential Revision: https://phab.nylas.com/D4023 --- .../search-index/lib/thread-search-index-store.es6 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/client-app/internal_packages/search-index/lib/thread-search-index-store.es6 b/packages/client-app/internal_packages/search-index/lib/thread-search-index-store.es6 index c48c18477..0c3dd4b80 100644 --- a/packages/client-app/internal_packages/search-index/lib/thread-search-index-store.es6 +++ b/packages/client-app/internal_packages/search-index/lib/thread-search-index-store.es6 @@ -122,12 +122,21 @@ class ThreadSearchIndexStore { if (change.objectClass !== Thread.name) { return; } - _.defer(() => { + _.defer(async () => { const {objects, type} = change const threads = objects; let promises = [] if (type === 'persist') { + const alreadyIndexedThreads = threads.filter(t => t.isSearchIndexed) + if (alreadyIndexedThreads.length > 0) { + alreadyIndexedThreads.forEach(thread => { + // Mark already indexed threads as unindexed so that we re-index them + // with updates + thread.isSearchIndexed = false + }) + await DatabaseStore.inTransaction(t => t.persistModels(alreadyIndexedThreads)) + } this.indexer.notifyHasIndexingToDo(); } else if (type === 'unpersist') { promises = threads.map(thread => this.unindexThread(thread,