fix(thread-search): Only rebuild index when # of accounts has changed

This commit is contained in:
Juan Tejada 2016-04-05 12:14:41 -07:00
parent ca5caec97e
commit b445f09854

View file

@ -18,15 +18,15 @@ const MESSAGE_BODY_LENGTH = 50000
class SearchIndexStore { class SearchIndexStore {
constuctor() { constuctor() {
this.accountIds = _.pluck(AccountStore.accounts(), 'id')
this.unsubscribers = [] this.unsubscribers = []
} }
activate() { activate() {
NylasSyncStatusStore.whenSyncComplete().then(() => { NylasSyncStatusStore.whenSyncComplete().then(() => {
const date = Date.now() const date = Date.now()
const accountIds = AccountStore.accounts().map(acc => acc.id)
console.log('ThreadSearch: Initializing thread search index...') console.log('ThreadSearch: Initializing thread search index...')
this.initializeIndex(accountIds) this.initializeIndex(this.accountIds)
.then(() => { .then(() => {
console.log('ThreadSearch: Index built successfully in ' + ((Date.now() - date) / 1000) + 's') console.log('ThreadSearch: Index built successfully in ' + ((Date.now() - date) / 1000) + 's')
this.unsubscribers = [ this.unsubscribers = [
@ -56,9 +56,14 @@ class SearchIndexStore {
onAccountsChanged() { onAccountsChanged() {
const date = Date.now() const date = Date.now()
const accountIds = AccountStore.accounts().map(acc => acc.id) const newIds = _.pluck(AccountStore.accounts(), 'id')
return this.clearIndex() if (newIds.length === this.accountIds.length) {
.then(() => this.buildIndex(accountIds)) return;
}
this.accountIds = newIds
this.clearIndex()
.then(() => this.buildIndex(this.accountIds))
.then(() => { .then(() => {
console.log('ThreadSearch: Index rebuilt successfully in ' + ((Date.now() - date) / 1000) + 's') console.log('ThreadSearch: Index rebuilt successfully in ' + ((Date.now() - date) / 1000) + 's')
}) })