Merged PR 1821: Refactor getCachedData method to be asynchronous and improve cache handling

Refactor getCachedData method to be asynchronous and improve cache handling
This commit is contained in:
Nino Righi
2024-11-27 14:20:24 +00:00
committed by Lorenz Hilpert
parent 9ba05253e9
commit 34e96f0751

View File

@@ -166,6 +166,7 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
if (!isEqual(cleanQueryParams, this.cleanupQueryParams(this.searchService.filter.getQueryParams()))) {
await this.searchService.setDefaultFilter(queryParams);
const data = await this.getCachedData(processId, queryParams, selectedBranch?.id);
if (data.items?.length > 0) {
this.searchService.setItems(data.items);
this.searchService.setHits(data.hits);
@@ -392,15 +393,14 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
});
}
getCachedData(processId: number, params: Record<string, string> = {}, branchId: number) {
async getCachedData(processId: number, params: Record<string, string> = {}, branchId: number) {
const qparams = this.cleanupQueryParams({ ...params, processId: String(processId), branchId: String(branchId) });
const cacheData = await this.cache.get<{
items: ItemDTO[];
hits: number;
}>(qparams);
return (
this.cache.get<{
items: ItemDTO[];
hits: number;
}>(qparams) || { items: [], hits: 0 }
);
return cacheData ?? { items: [], hits: 0 };
}
cleanupQueryParams(params: Record<string, string> = {}) {