Add: Cache full Category list
This commit is contained in:
parent
e62ee40950
commit
33aa98e456
@ -45,6 +45,10 @@ export const getCategoriesCachedByRef = refExtendCachedMethod(getCategoriesCache
|
||||
export async function getCategories(category_ids = undefined) {
|
||||
if (category_ids !== undefined && category_ids.length == 0) return new Map();
|
||||
|
||||
if (category_ids === undefined && cache.has('all')) {
|
||||
return /** @type {Result<Category>} */ (cache.get('all'));
|
||||
}
|
||||
|
||||
const filter = category_ids ? sql`WHERE id IN ${ sql(category_ids) }` : sql``;
|
||||
|
||||
const query = sql`
|
||||
@ -61,7 +65,11 @@ export async function getCategories(category_ids = undefined) {
|
||||
|
||||
categories.forEach(row => {
|
||||
result.set(row['id'], parseCategoryFromRow(row));
|
||||
})
|
||||
});
|
||||
|
||||
if (category_ids === undefined) {
|
||||
cache.set('all', result);
|
||||
}
|
||||
|
||||
return updateCategoryCache(result);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user