diff --git a/src/abstractions/search.service.ts b/src/abstractions/search.service.ts index 127a970353..fe60532963 100644 --- a/src/abstractions/search.service.ts +++ b/src/abstractions/search.service.ts @@ -4,7 +4,7 @@ import { SendView } from '../models/view/sendView'; export abstract class SearchService { clearIndex: () => void; isSearchable: (query: string) => boolean; - indexCiphers: () => Promise; + indexCiphers: (ciphersToIndex?: CipherView[]) => Promise; searchCiphers: (query: string, filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), ciphers?: CipherView[]) => Promise; diff --git a/src/angular/components/ciphers.component.ts b/src/angular/components/ciphers.component.ts index 94330da652..0fe3c35e46 100644 --- a/src/angular/components/ciphers.component.ts +++ b/src/angular/components/ciphers.component.ts @@ -77,20 +77,20 @@ export class CiphersComponent { await this.search(null); } - async search(timeout: number = null) { + async search(timeout: number = null, indexedCiphers?: CipherView[]) { this.searchPending = false; if (this.searchTimeout != null) { clearTimeout(this.searchTimeout); } const deletedFilter: (cipher: CipherView) => boolean = c => c.isDeleted === this.deleted; if (timeout == null) { - this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], null); + this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], indexedCiphers); await this.resetPaging(); return; } this.searchPending = true; this.searchTimeout = setTimeout(async () => { - this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], null); + this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, deletedFilter], indexedCiphers); await this.resetPaging(); this.searchPending = false; }, timeout); diff --git a/src/services/search.service.ts b/src/services/search.service.ts index fee647dc5c..0c82e1286e 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -28,7 +28,7 @@ export class SearchService implements SearchServiceAbstraction { return !notSearchable; } - async indexCiphers(): Promise { + async indexCiphers(ciphers?: CipherView[]): Promise { if (this.indexing) { return; } @@ -60,7 +60,7 @@ export class SearchService implements SearchServiceAbstraction { builder.field('attachments_joined', { extractor: (c: CipherView) => this.attachmentExtractor(c, true) }); builder.field('organizationid', { extractor: (c: CipherView) => c.organizationId }); - const ciphers = await this.cipherService.getAllDecrypted(); + ciphers = ciphers || await this.cipherService.getAllDecrypted(); ciphers.forEach(c => builder.add(c)); this.index = builder.build(); this.indexing = false;