fix: finer granularity cache key for dynamic assets

This commit is contained in:
Sunho Kim
2024-07-15 08:20:33 -07:00
parent ba19470a76
commit edfe6f93fc

View File

@@ -214,16 +214,17 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
for(const match of matches){ for(const match of matches){
const type = match[1] const type = match[1]
const assetName = match[2] const assetName = match[2]
const cacheKey = char.chaId + '::' + assetName
if(type !== 'emotion' && type !== 'source'){ if(type !== 'emotion' && type !== 'source'){
if(bestMatchCache.has(assetName)){ if(bestMatchCache.has(cacheKey)){
data = data.replaceAll(match[0], `{{${type}::${bestMatchCache.get(assetName)}}}`) data = data.replaceAll(match[0], `{{${type}::${bestMatchCache.get(cacheKey)}}}`)
} }
else if(!assetNames.includes(assetName)){ else if(!assetNames.includes(assetName)){
const searched = await processer.similaritySearch(assetName) const searched = await processer.similaritySearch(assetName)
const bestMatch = searched[0] const bestMatch = searched[0]
if(bestMatch){ if(bestMatch){
data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`) data = data.replaceAll(match[0], `{{${type}::${bestMatch}}}`)
bestMatchCache.set(assetName, bestMatch) bestMatchCache.set(cacheKey, bestMatch)
} }
} }
} }