0
0

perf(frontend): cache user lists

This commit is contained in:
syuilo 2023-03-24 16:58:57 +09:00
parent 5f52b13325
commit cabed6098d
4 changed files with 10 additions and 4 deletions

View File

@ -3,3 +3,4 @@ import { Cache } from '@/scripts/cache';
export const clipsCache = new Cache<misskey.entities.Clip[]>(Infinity);
export const rolesCache = new Cache(Infinity);
export const userListsCache = new Cache<misskey.entities.UserList[]>(Infinity);

View File

@ -24,6 +24,7 @@ import MkAvatars from '@/components/MkAvatars.vue';
import * as os from '@/os';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { userListsCache } from '@/cache';
const pagingComponent = $shallowRef<InstanceType<typeof MkPagination>>();
@ -38,6 +39,7 @@ async function create() {
});
if (canceled) return;
await os.apiWithDialog('users/lists/create', { name: name });
userListsCache.delete();
pagingComponent.reload();
}

View File

@ -37,6 +37,7 @@ import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n';
import { userPage } from '@/filters/user';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import { userListsCache } from '@/cache';
const props = defineProps<{
listId: string;
@ -97,6 +98,8 @@ async function renameList() {
name: name,
});
userListsCache.delete();
list.name = name;
}
@ -107,10 +110,10 @@ async function deleteList() {
});
if (canceled) return;
await os.api('users/lists/delete', {
await os.apiWithDialog('users/lists/delete', {
listId: list.id,
});
os.success();
userListsCache.delete();
mainRouter.push('/my/lists');
}

View File

@ -8,7 +8,7 @@ import { userActions } from '@/store';
import { $i, iAmModerator } from '@/account';
import { mainRouter } from '@/router';
import { Router } from '@/nirax';
import { rolesCache } from '@/cache';
import { rolesCache, userListsCache } from '@/cache';
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
const meId = $i ? $i.id : null;
@ -127,7 +127,7 @@ export function getUserMenu(user: misskey.entities.UserDetailed, router: Router
icon: 'ti ti-list',
text: i18n.ts.addToList,
children: async () => {
const lists = await os.api('users/lists/list');
const lists = await userListsCache.fetch(() => os.api('users/lists/list'));
return lists.map(list => ({
text: list.name,