perf(frontend): cache user lists
This commit is contained in:
parent
5f52b13325
commit
cabed6098d
4 changed files with 10 additions and 4 deletions
|
@ -3,3 +3,4 @@ import { Cache } from '@/scripts/cache';
|
||||||
|
|
||||||
export const clipsCache = new Cache<misskey.entities.Clip[]>(Infinity);
|
export const clipsCache = new Cache<misskey.entities.Clip[]>(Infinity);
|
||||||
export const rolesCache = new Cache(Infinity);
|
export const rolesCache = new Cache(Infinity);
|
||||||
|
export const userListsCache = new Cache<misskey.entities.UserList[]>(Infinity);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import MkAvatars from '@/components/MkAvatars.vue';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { definePageMetadata } from '@/scripts/page-metadata';
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
||||||
|
import { userListsCache } from '@/cache';
|
||||||
|
|
||||||
const pagingComponent = $shallowRef<InstanceType<typeof MkPagination>>();
|
const pagingComponent = $shallowRef<InstanceType<typeof MkPagination>>();
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ async function create() {
|
||||||
});
|
});
|
||||||
if (canceled) return;
|
if (canceled) return;
|
||||||
await os.apiWithDialog('users/lists/create', { name: name });
|
await os.apiWithDialog('users/lists/create', { name: name });
|
||||||
|
userListsCache.delete();
|
||||||
pagingComponent.reload();
|
pagingComponent.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ import { definePageMetadata } from '@/scripts/page-metadata';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { userPage } from '@/filters/user';
|
import { userPage } from '@/filters/user';
|
||||||
import MkUserCardMini from '@/components/MkUserCardMini.vue';
|
import MkUserCardMini from '@/components/MkUserCardMini.vue';
|
||||||
|
import { userListsCache } from '@/cache';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
listId: string;
|
listId: string;
|
||||||
|
@ -97,6 +98,8 @@ async function renameList() {
|
||||||
name: name,
|
name: name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
userListsCache.delete();
|
||||||
|
|
||||||
list.name = name;
|
list.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,10 +110,10 @@ async function deleteList() {
|
||||||
});
|
});
|
||||||
if (canceled) return;
|
if (canceled) return;
|
||||||
|
|
||||||
await os.api('users/lists/delete', {
|
await os.apiWithDialog('users/lists/delete', {
|
||||||
listId: list.id,
|
listId: list.id,
|
||||||
});
|
});
|
||||||
os.success();
|
userListsCache.delete();
|
||||||
mainRouter.push('/my/lists');
|
mainRouter.push('/my/lists');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { userActions } from '@/store';
|
||||||
import { $i, iAmModerator } from '@/account';
|
import { $i, iAmModerator } from '@/account';
|
||||||
import { mainRouter } from '@/router';
|
import { mainRouter } from '@/router';
|
||||||
import { Router } from '@/nirax';
|
import { Router } from '@/nirax';
|
||||||
import { rolesCache } from '@/cache';
|
import { rolesCache, userListsCache } from '@/cache';
|
||||||
|
|
||||||
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
|
export function getUserMenu(user: misskey.entities.UserDetailed, router: Router = mainRouter) {
|
||||||
const meId = $i ? $i.id : null;
|
const meId = $i ? $i.id : null;
|
||||||
|
@ -127,7 +127,7 @@ export function getUserMenu(user: misskey.entities.UserDetailed, router: Router
|
||||||
icon: 'ti ti-list',
|
icon: 'ti ti-list',
|
||||||
text: i18n.ts.addToList,
|
text: i18n.ts.addToList,
|
||||||
children: async () => {
|
children: async () => {
|
||||||
const lists = await os.api('users/lists/list');
|
const lists = await userListsCache.fetch(() => os.api('users/lists/list'));
|
||||||
|
|
||||||
return lists.map(list => ({
|
return lists.map(list => ({
|
||||||
text: list.name,
|
text: list.name,
|
||||||
|
|
Loading…
Reference in a new issue