mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 06:43:51 +02:00
add cleanup function for user ccache and world cache
This commit is contained in:
@@ -389,6 +389,49 @@ export const useUserStore = defineStore('User', () => {
|
||||
}
|
||||
|
||||
const robotUrl = `${AppDebug.endpointDomain}/file/file_0e8c4e32-7444-44ea-ade4-313c010d4bae/1/file`;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Map<string, any>} userCache
|
||||
* @param {Map<string, any>} friendMap
|
||||
*/
|
||||
function cleanupUserCache(userCache, friendMap) {
|
||||
const bufferSize = 200;
|
||||
|
||||
const currentFriendCount = friendMap.size;
|
||||
const currentTotalSize = userCache.size;
|
||||
|
||||
const effectiveMaxSize = currentFriendCount + bufferSize;
|
||||
|
||||
if (currentTotalSize <= effectiveMaxSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetDeleteCount = currentTotalSize - effectiveMaxSize;
|
||||
let deletedCount = 0;
|
||||
const keysToDelete = [];
|
||||
|
||||
for (const userId of userCache.keys()) {
|
||||
if (friendMap.has(userId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (deletedCount >= targetDeleteCount) {
|
||||
break;
|
||||
}
|
||||
|
||||
keysToDelete.push(userId);
|
||||
deletedCount++;
|
||||
}
|
||||
|
||||
for (const id of keysToDelete) {
|
||||
userCache.delete(id);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`User cache cleanup: Deleted ${deletedCount}. Current cache size: ${userCache.size}`
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {import('../types/api/user').GetUserResponse} json
|
||||
@@ -506,6 +549,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
ref.$customTag = '';
|
||||
ref.$customTagColour = '';
|
||||
}
|
||||
cleanupUserCache(cachedUsers, friendStore.friends);
|
||||
cachedUsers.set(ref.id, ref);
|
||||
friendStore.updateFriend(ref.id);
|
||||
} else {
|
||||
|
||||
@@ -215,6 +215,23 @@ export const useWorldStore = defineStore('World', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupWorldCache(WorldCache) {
|
||||
const maxCacheSize = 10000;
|
||||
|
||||
if (WorldCache.size <= maxCacheSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
const deletedCount = WorldCache.size - maxCacheSize;
|
||||
while (WorldCache.size > maxCacheSize) {
|
||||
const deletedKey = WorldCache.keys().next().value;
|
||||
WorldCache.delete(deletedKey);
|
||||
}
|
||||
console.log(
|
||||
`World cache cleanup: Deleted ${deletedCount}. Current cache size: ${WorldCache.size}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} json
|
||||
@@ -270,6 +287,7 @@ export const useWorldStore = defineStore('World', () => {
|
||||
//
|
||||
...json
|
||||
};
|
||||
cleanupWorldCache(cachedWorlds);
|
||||
cachedWorlds.set(ref.id, ref);
|
||||
} else {
|
||||
Object.assign(ref, json);
|
||||
|
||||
Reference in New Issue
Block a user