From edfe6f93fc1a7131fd295bb24bc637a73f6191e3 Mon Sep 17 00:00:00 2001 From: Sunho Kim Date: Mon, 15 Jul 2024 08:20:33 -0700 Subject: [PATCH] fix: finer granularity cache key for dynamic assets --- src/ts/process/scripts.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ts/process/scripts.ts b/src/ts/process/scripts.ts index 256d7269..9b4c0016 100644 --- a/src/ts/process/scripts.ts +++ b/src/ts/process/scripts.ts @@ -214,16 +214,17 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter for(const match of matches){ const type = match[1] const assetName = match[2] + const cacheKey = char.chaId + '::' + assetName if(type !== 'emotion' && type !== 'source'){ - if(bestMatchCache.has(assetName)){ - data = data.replaceAll(match[0], `{{${type}::${bestMatchCache.get(assetName)}}}`) + if(bestMatchCache.has(cacheKey)){ + data = data.replaceAll(match[0], `{{${type}::${bestMatchCache.get(cacheKey)}}}`) } else if(!assetNames.includes(assetName)){ const searched = await processer.similaritySearch(assetName) const bestMatch = searched[0] if(bestMatch){ data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`) - bestMatchCache.set(assetName, bestMatch) + bestMatchCache.set(cacheKey, bestMatch) } } }