From f8daa6ff4cc7fedea8ca8ce2b75010766c078b6f Mon Sep 17 00:00:00 2001 From: pa Date: Tue, 20 Jan 2026 23:52:46 +0900 Subject: [PATCH] add cleanInstanceCache --- src/stores/instance.js | 27 +++++++++++++++++++++++++++ src/stores/user.js | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/stores/instance.js b/src/stores/instance.js index f1195498..264f67da 100644 --- a/src/stores/instance.js +++ b/src/stores/instance.js @@ -55,6 +55,32 @@ export const useInstanceStore = defineStore('Instance', () => { let cachedInstances = new Map(); + function cleanInstanceCache() { + const maxSize = 200; + if (cachedInstances.size <= maxSize) { + return; + } + const removable = []; + cachedInstances.forEach((ref, id) => { + if ( + [...friendStore.friends.values()].some( + (f) => f.$location?.tag === id + ) + ) { + return; + } + removable.push({ + id, + fetchedAt: Date.parse(ref.$fetchedAt) || 0 + }); + }); + removable.sort((a, b) => a.fetchedAt - b.fetchedAt); + const overBy = cachedInstances.size - maxSize; + for (let i = 0; i < overBy && i < removable.length; i++) { + cachedInstances.delete(removable[i].id); + } + } + const lastInstanceApplied = ref(''); const currentInstanceWorld = ref({ @@ -326,6 +352,7 @@ export const useInstanceStore = defineStore('Instance', () => { ...json }; cachedInstances.set(ref.id, ref); + cleanInstanceCache(); } else { Object.assign(ref, json); } diff --git a/src/stores/user.js b/src/stores/user.js index ce6f1601..5fb81ccf 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -411,7 +411,7 @@ export const useUserStore = defineStore('User', () => { * @param {Map} friendMap */ function cleanupUserCache(userCache, friendMap) { - const bufferSize = 200; + const bufferSize = 300; const currentFriendCount = friendMap.size; const currentTotalSize = userCache.size;