From 5be76c1a6345f9c9222fb2bd2f663d7a796ed690 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Fri, 23 Apr 2021 13:55:57 -0500 Subject: [PATCH] Allow external awaits of indexing (#359) * Allow external awaits of indexing We were getting stuck in an infinite load loop where we were basing logic on a dirty state of search service. This await enables us to wait until an index is complete, then update it rather than being kicked out of indexing early because it is in progress. * Stop infinite loop by specifying ciphers to index --- src/services/cipher.service.ts | 2 +- src/services/search.service.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 37b47d430b..92de470aa2 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -297,7 +297,7 @@ export class CipherService implements CipherServiceAbstraction { const userId = await this.userService.getUserId(); if ((this.searchService().indexedEntityId ?? userId) !== userId) { - await this.searchService().indexCiphers(); + await this.searchService().indexCiphers(userId, this.decryptedCipherCache); } return this.decryptedCipherCache; } diff --git a/src/services/search.service.ts b/src/services/search.service.ts index 58b4c96efd..454ee29097 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -26,6 +26,7 @@ export class SearchService implements SearchServiceAbstraction { } clearIndex(): void { + this.indexedEntityId = null; this.index = null; } @@ -42,6 +43,7 @@ export class SearchService implements SearchServiceAbstraction { this.logService.time('search indexing'); this.indexing = true; + this.indexedEntityId = indexedEntityId; this.index = null; const builder = new lunr.Builder(); builder.ref('id'); @@ -70,7 +72,7 @@ export class SearchService implements SearchServiceAbstraction { ciphers = ciphers || await this.cipherService.getAllDecrypted(); ciphers.forEach(c => builder.add(c)); this.index = builder.build(); - this.indexedEntityId = indexedEntityId; + this.indexing = false; this.logService.timeEnd('search indexing');