1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

Pass ciphers to index and indexed ciphers to search service (#318)

This commit is contained in:
Matt Gibson
2021-04-02 16:32:30 -05:00
committed by GitHub
parent f4f00b1eb2
commit bc7bd5bd3f
3 changed files with 6 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import { SendView } from '../models/view/sendView';
export abstract class SearchService { export abstract class SearchService {
clearIndex: () => void; clearIndex: () => void;
isSearchable: (query: string) => boolean; isSearchable: (query: string) => boolean;
indexCiphers: () => Promise<void>; indexCiphers: (ciphersToIndex?: CipherView[]) => Promise<void>;
searchCiphers: (query: string, searchCiphers: (query: string,
filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]),
ciphers?: CipherView[]) => Promise<CipherView[]>; ciphers?: CipherView[]) => Promise<CipherView[]>;

View File

@@ -77,20 +77,20 @@ export class CiphersComponent {
await this.search(null); await this.search(null);
} }
async search(timeout: number = null) { async search(timeout: number = null, indexedCiphers?: CipherView[]) {
this.searchPending = false; this.searchPending = false;
if (this.searchTimeout != null) { if (this.searchTimeout != null) {
clearTimeout(this.searchTimeout); clearTimeout(this.searchTimeout);
} }
const deletedFilter: (cipher: CipherView) => boolean = c => c.isDeleted === this.deleted; const deletedFilter: (cipher: CipherView) => boolean = c => c.isDeleted === this.deleted;
if (timeout == null) { 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(); await this.resetPaging();
return; return;
} }
this.searchPending = true; this.searchPending = true;
this.searchTimeout = setTimeout(async () => { 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(); await this.resetPaging();
this.searchPending = false; this.searchPending = false;
}, timeout); }, timeout);

View File

@@ -28,7 +28,7 @@ export class SearchService implements SearchServiceAbstraction {
return !notSearchable; return !notSearchable;
} }
async indexCiphers(): Promise<void> { async indexCiphers(ciphers?: CipherView[]): Promise<void> {
if (this.indexing) { if (this.indexing) {
return; return;
} }
@@ -60,7 +60,7 @@ export class SearchService implements SearchServiceAbstraction {
builder.field('attachments_joined', builder.field('attachments_joined',
{ extractor: (c: CipherView) => this.attachmentExtractor(c, true) }); { extractor: (c: CipherView) => this.attachmentExtractor(c, true) });
builder.field('organizationid', { extractor: (c: CipherView) => c.organizationId }); 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)); ciphers.forEach(c => builder.add(c));
this.index = builder.build(); this.index = builder.build();
this.indexing = false; this.indexing = false;