From f6e07e2cca2a2cddba36b2914cf3df2f3bc7f6bc Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 13 Dec 2025 21:07:29 +0000 Subject: [PATCH] Refactored caching utility: replaced jsonToCacheKey with getQueryToCacheKey for improved cache key generation based on model, id, and populate parameters. --- src/utils.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index 31e7a1c..1cf2a74 100644 --- a/src/utils.js +++ b/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(',')}`; }