mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-11 19:03:51 +02:00
add cleanInstanceCache
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
* @param {Map<string, any>} friendMap
|
||||
*/
|
||||
function cleanupUserCache(userCache, friendMap) {
|
||||
const bufferSize = 200;
|
||||
const bufferSize = 300;
|
||||
|
||||
const currentFriendCount = friendMap.size;
|
||||
const currentTotalSize = userCache.size;
|
||||
|
||||
Reference in New Issue
Block a user