diff --git a/src/abstractions/search.service.ts b/src/abstractions/search.service.ts index fe60532963e..d95bea418ec 100644 --- a/src/abstractions/search.service.ts +++ b/src/abstractions/search.service.ts @@ -2,9 +2,10 @@ import { CipherView } from '../models/view/cipherView'; import { SendView } from '../models/view/sendView'; export abstract class SearchService { + indexedEntityId?: string = null; clearIndex: () => void; isSearchable: (query: string) => boolean; - indexCiphers: (ciphersToIndex?: CipherView[]) => Promise; + indexCiphers: (indexedEntityGuid?: string, ciphersToIndex?: CipherView[]) => Promise; searchCiphers: (query: string, filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), ciphers?: CipherView[]) => Promise; diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 7ba468caca2..37b47d430b5 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -294,6 +294,11 @@ export class CipherService implements CipherServiceAbstraction { @sequentialize(() => 'getAllDecrypted') async getAllDecrypted(): Promise { if (this.decryptedCipherCache != null) { + const userId = await this.userService.getUserId(); + if ((this.searchService().indexedEntityId ?? userId) !== userId) + { + await this.searchService().indexCiphers(); + } return this.decryptedCipherCache; } diff --git a/src/services/search.service.ts b/src/services/search.service.ts index f593e08bbf4..58b4c96efda 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -13,6 +13,7 @@ import { UriMatchType } from '../enums/uriMatchType'; import { SendView } from '../models/view/sendView'; export class SearchService implements SearchServiceAbstraction { + indexedEntityId?: string = null; private indexing = false; private index: lunr.Index = null; private searchableMinLength = 2; @@ -34,7 +35,7 @@ export class SearchService implements SearchServiceAbstraction { return !notSearchable; } - async indexCiphers(ciphers?: CipherView[]): Promise { + async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise { if (this.indexing) { return; } @@ -69,6 +70,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');