diff --git a/src/ts/util.ts b/src/ts/util.ts index dda5078c..a4fb99f7 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -16,70 +16,24 @@ export interface Messagec extends Message{ index: number } -// Map to store message caches for each character -const messageFormCacheMap = new Map>(); - -// Function to initialize the cache (called when changing characters) -export function clearMessageFormCache(charId?: number) { - if (charId !== undefined) { - messageFormCacheMap.delete(charId); - } else { - messageFormCacheMap.clear(); - } -} - export function messageForm(arg:Message[], loadPages:number){ - let db = getDatabase() - let selectedChar = get(selectedCharID) - - // Map for message caching (maintained as a static variable) - const messageCache = messageFormCacheMap.get(selectedChar) || new Map(); - function reformatContent(data:string){ return data.trim() } let a:Messagec[] = [] - const startIndex = Math.max(0, arg.length - loadPages); - - // Process only necessary messages (up to loadPages) - for(let i = arg.length - 1; i >= startIndex; i--){ - const m = arg[i]; - const cacheKey = `${m.role}-${i}-${m.chatId || 'none'}-${m.data.length}`; - - // Use cached result if available - if (messageCache.has(cacheKey)) { - a.push(messageCache.get(cacheKey)); - continue; - } - - // Create new if not cached - const processed: Messagec = { + for(let i=0;i 1000) { - const keys = Array.from(messageCache.keys()); - for (let i = 0; i < keys.length - 1000; i++) { - messageCache.delete(keys[i]); - } - } - - return a; + return a.slice(0, loadPages) } export function sleep(ms: number) {