mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 06:43:51 +02:00
add cleanInstanceCache
This commit is contained in:
@@ -55,6 +55,32 @@ export const useInstanceStore = defineStore('Instance', () => {
|
|||||||
|
|
||||||
let cachedInstances = new Map();
|
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 lastInstanceApplied = ref('');
|
||||||
|
|
||||||
const currentInstanceWorld = ref({
|
const currentInstanceWorld = ref({
|
||||||
@@ -326,6 +352,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
|||||||
...json
|
...json
|
||||||
};
|
};
|
||||||
cachedInstances.set(ref.id, ref);
|
cachedInstances.set(ref.id, ref);
|
||||||
|
cleanInstanceCache();
|
||||||
} else {
|
} else {
|
||||||
Object.assign(ref, json);
|
Object.assign(ref, json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ export const useUserStore = defineStore('User', () => {
|
|||||||
* @param {Map<string, any>} friendMap
|
* @param {Map<string, any>} friendMap
|
||||||
*/
|
*/
|
||||||
function cleanupUserCache(userCache, friendMap) {
|
function cleanupUserCache(userCache, friendMap) {
|
||||||
const bufferSize = 200;
|
const bufferSize = 300;
|
||||||
|
|
||||||
const currentFriendCount = friendMap.size;
|
const currentFriendCount = friendMap.size;
|
||||||
const currentTotalSize = userCache.size;
|
const currentTotalSize = userCache.size;
|
||||||
|
|||||||
Reference in New Issue
Block a user