1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-24143] Search performance improvements (#16070)

* [PM-24143] Add perUserCache$ to SearchService index$

* [PM-24143] Cleanup and optimize isSearchable

* [PM-24143] Remove unused search flags and subscription from the vault-items component

* [PM-24143] Add search text for desktop vault items. Consolidate SearchTextDebounceInterval constant to SearchService

* [PM-24143] Ensure cipher search indexing is non-blocking

* [PM-24143] Remove redundant index ciphers operation

* [PM-24143] Add search performance measurements

* [PM-24143] Remove artificial delay

* [PM-24143] Remove startWith from index$ to avoid basic search with lunr queries

* [PM-24143] Re-organize isSearchable to check long lunr queries for index existence
This commit is contained in:
Shane Melton
2025-08-22 09:32:36 -07:00
committed by GitHub
parent ba7e5fdcde
commit 4676a122da
8 changed files with 147 additions and 46 deletions

View File

@@ -1,18 +1,16 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angular/core";
import { Directive, EventEmitter, Input, OnDestroy, Output } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import {
BehaviorSubject,
Subject,
combineLatest,
filter,
from,
map,
of,
shareReplay,
switchMap,
takeUntil,
} from "rxjs";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
@@ -29,7 +27,7 @@ import {
} from "@bitwarden/common/vault/utils/cipher-view-like-utils";
@Directive()
export class VaultItemsComponent<C extends CipherViewLike> implements OnInit, OnDestroy {
export class VaultItemsComponent<C extends CipherViewLike> implements OnDestroy {
@Input() activeCipherId: string = null;
@Output() onCipherClicked = new EventEmitter<C>();
@Output() onCipherRightClicked = new EventEmitter<C>();
@@ -55,12 +53,9 @@ export class VaultItemsComponent<C extends CipherViewLike> implements OnInit, On
shareReplay({ bufferSize: 1, refCount: true }),
);
protected searchPending = false;
/** Construct filters as an observable so it can be appended to the cipher stream. */
private _filter$ = new BehaviorSubject<(cipher: C) => boolean | null>(null);
private destroy$ = new Subject<void>();
private isSearchable: boolean = false;
private _searchText$ = new BehaviorSubject<string>("");
get searchText() {
@@ -87,19 +82,6 @@ export class VaultItemsComponent<C extends CipherViewLike> implements OnInit, On
this.subscribeToCiphers();
}
async ngOnInit() {
combineLatest([getUserId(this.accountService.activeAccount$), this._searchText$])
.pipe(
switchMap(([userId, searchText]) =>
from(this.searchService.isSearchable(userId, searchText)),
),
takeUntil(this.destroy$),
)
.subscribe((isSearchable) => {
this.isSearchable = isSearchable;
});
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
@@ -140,10 +122,6 @@ export class VaultItemsComponent<C extends CipherViewLike> implements OnInit, On
this.onAddCipherOptions.emit();
}
isSearching() {
return !this.searchPending && this.isSearchable;
}
protected deletedFilter: (cipher: C) => boolean = (c) =>
CipherViewLikeUtils.isDeleted(c) === this.deleted;