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