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];
|
return modelList.filter(model => model.modelName == modelName)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function jsonToCacheKey(obj) {
|
export function getQueryToCacheKey({ model, id, populate }) {
|
||||||
const normalized = canonicalize(obj);
|
const populateKey = [];
|
||||||
const hash = crypto.createHash('sha256').update(normalized).digest('hex');
|
for (const pop of populate) {
|
||||||
return hash;
|
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