Optimize topbar search for better performance (#1161)
This commit is contained in:
@@ -16,7 +16,7 @@ export class HeaderFilter implements BookFilter {
|
||||
distinctUntilChanged(),
|
||||
switchMap(term => {
|
||||
const normalizedTerm = normalize(term || '').trim();
|
||||
if (!normalizedTerm) {
|
||||
if (normalizedTerm.length < 2) {
|
||||
return of(bookState);
|
||||
}
|
||||
return of(normalizedTerm).pipe(
|
||||
|
||||
@@ -53,7 +53,10 @@ export class BookSearcherComponent implements OnInit, OnDestroy {
|
||||
})
|
||||
).subscribe({
|
||||
next: (filteredState) => {
|
||||
this.books = this.searchQuery.trim() ? (filteredState.books || []) : [];
|
||||
const term = this.searchQuery.trim();
|
||||
this.books = term.length >= 2
|
||||
? (filteredState.books || []).slice(0, 50)
|
||||
: [];
|
||||
},
|
||||
error: (error) => console.error('Subscription error:', error)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user