mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-17 13:53:52 +02:00
improve avatar time spent loading performance by fetching all times in one query
This commit is contained in:
@@ -53,6 +53,18 @@ const avatarFavorites = {
|
||||
return ref;
|
||||
},
|
||||
|
||||
async getAllAvatarTimeSpent() {
|
||||
const map = new Map();
|
||||
await sqliteService.execute(
|
||||
(row) => {
|
||||
map.set(row[0], row[1] || 0);
|
||||
},
|
||||
`SELECT avatar_id, time FROM ${dbVars.userPrefix}_avatar_history`
|
||||
);
|
||||
|
||||
return map;
|
||||
},
|
||||
|
||||
addAvatarTimeSpent(avatarId, timeSpent) {
|
||||
sqliteService.executeNonQuery(
|
||||
`UPDATE ${dbVars.userPrefix}_avatar_history SET time = time + @timeSpent WHERE avatar_id = @avatarId`,
|
||||
|
||||
@@ -839,18 +839,18 @@
|
||||
const list = Array.from(map.values());
|
||||
const currentAvatarId = currentUser.value.currentAvatar;
|
||||
const swapTime = currentUser.value.$previousAvatarSwapTime;
|
||||
const tagsMap = await database.getAllAvatarTags();
|
||||
const [tagsMap, avatarTimeSpentMap] = await Promise.all([
|
||||
database.getAllAvatarTags(),
|
||||
database.getAllAvatarTimeSpent()
|
||||
]);
|
||||
avatarTagsMap.value = tagsMap;
|
||||
await Promise.all(
|
||||
list.map(async (ref) => {
|
||||
const aviTime = await database.getAvatarTimeSpent(ref.id);
|
||||
ref.$timeSpent = aviTime.timeSpent;
|
||||
if (ref.id === currentAvatarId && swapTime) {
|
||||
ref.$timeSpent += Date.now() - swapTime;
|
||||
}
|
||||
ref.$tags = tagsMap.get(ref.id) || [];
|
||||
})
|
||||
);
|
||||
for (const ref of list) {
|
||||
ref.$timeSpent = avatarTimeSpentMap.get(ref.id) || 0;
|
||||
if (ref.id === currentAvatarId && swapTime) {
|
||||
ref.$timeSpent += Date.now() - swapTime;
|
||||
}
|
||||
ref.$tags = tagsMap.get(ref.id) || [];
|
||||
}
|
||||
avatars.value = list;
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user