Refactored caching utility: replaced jsonToCacheKey with getQueryToCacheKey for improved cache key generation based on model, id, and populate parameters.
This commit is contained in:
parent
94e0614852
commit
f6e07e2cca
14
src/utils.js
14
src/utils.js
@ -76,8 +76,14 @@ export function getModelByName(modelName) {
|
||||
return modelList.filter(model => model.modelName == modelName)[0];
|
||||
}
|
||||
|
||||
export function jsonToCacheKey(obj) {
|
||||
const normalized = canonicalize(obj);
|
||||
const hash = crypto.createHash('sha256').update(normalized).digest('hex');
|
||||
return hash;
|
||||
export function getQueryToCacheKey({ model, id, populate }) {
|
||||
const populateKey = [];
|
||||
for (const pop of populate) {
|
||||
if (typeof pop === 'string') {
|
||||
populateKey.push(pop);
|
||||
} else if (typeof pop === 'object') {
|
||||
populateKey.push(pop.path);
|
||||
}
|
||||
}
|
||||
return `${model}:${id?.toString()}-${populateKey.join(',')}`;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user