Skip to content

Commit d013e45

Browse files
enhance(frontend): お気に入りチャンネルをキャッシュするように (#13881)
1 parent 805a11a commit d013e45

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

packages/frontend/src/cache.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const clipsCache = new Cache<Misskey.entities.Clip[]>(1000 * 60 * 30, ()
1111
export const rolesCache = new Cache(1000 * 60 * 30, () => misskeyApi('admin/roles/list'));
1212
export const userListsCache = new Cache<Misskey.entities.UserList[]>(1000 * 60 * 30, () => misskeyApi('users/lists/list'));
1313
export const antennasCache = new Cache<Misskey.entities.Antenna[]>(1000 * 60 * 30, () => misskeyApi('antennas/list'));
14+
export const favoritedChannelsCache = new Cache<Misskey.entities.Channel[]>(1000 * 60 * 30, () => misskeyApi('channels/my-favorites', { limit: 100 }));

packages/frontend/src/pages/channel.vue

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
8383
import { deviceKind } from '@/scripts/device-kind.js';
8484
import MkNotes from '@/components/MkNotes.vue';
8585
import { url } from '@/config.js';
86+
import { favoritedChannelsCache } from '@/cache.js';
8687
import MkButton from '@/components/MkButton.vue';
8788
import MkInput from '@/components/MkInput.vue';
8889
import { defaultStore } from '@/store.js';
@@ -153,6 +154,7 @@ function favorite() {
153154
channelId: channel.value.id,
154155
}).then(() => {
155156
favorited.value = true;
157+
favoritedChannelsCache.delete();
156158
});
157159
}
158160

@@ -168,6 +170,7 @@ async function unfavorite() {
168170
channelId: channel.value.id,
169171
}).then(() => {
170172
favorited.value = false;
173+
favoritedChannelsCache.delete();
171174
});
172175
}
173176

packages/frontend/src/pages/timeline.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { i18n } from '@/i18n.js';
4848
import { instance } from '@/instance.js';
4949
import { $i } from '@/account.js';
5050
import { definePageMetadata } from '@/scripts/page-metadata.js';
51-
import { antennasCache, userListsCache } from '@/cache.js';
51+
import { antennasCache, userListsCache, favoritedChannelsCache } from '@/cache.js';
5252
import { deviceKind } from '@/scripts/device-kind.js';
5353
import { deepMerge } from '@/scripts/merge.js';
5454
import { MenuItem } from '@/types/menu.js';
@@ -173,9 +173,7 @@ async function chooseAntenna(ev: MouseEvent): Promise<void> {
173173
}
174174

175175
async function chooseChannel(ev: MouseEvent): Promise<void> {
176-
const channels = await misskeyApi('channels/my-favorites', {
177-
limit: 100,
178-
});
176+
const channels = await favoritedChannelsCache.fetch();
179177
const items: MenuItem[] = [
180178
...channels.map(channel => {
181179
const lastReadedAt = miLocalStorage.getItemAsJson(`channelLastReadedAt:${channel.id}`) ?? null;

packages/frontend/src/scripts/get-note-menu.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { url } from '@/config.js';
1616
import { defaultStore, noteActions } from '@/store.js';
1717
import { miLocalStorage } from '@/local-storage.js';
1818
import { getUserMenu } from '@/scripts/get-user-menu.js';
19-
import { clipsCache } from '@/cache.js';
19+
import { clipsCache, favoritedChannelsCache } from '@/cache.js';
2020
import { MenuItem } from '@/types/menu.js';
2121
import MkRippleEffect from '@/components/MkRippleEffect.vue';
2222
import { isSupportShare } from '@/scripts/navigator.js';
@@ -603,9 +603,7 @@ export function getRenoteMenu(props: {
603603
icon: 'ti ti-repeat',
604604
text: appearNote.channel ? i18n.ts.renoteToOtherChannel : i18n.ts.renoteToChannel,
605605
children: async () => {
606-
const channels = await misskeyApi('channels/my-favorites', {
607-
limit: 30,
608-
});
606+
const channels = await favoritedChannelsCache.fetch();
609607
return channels.filter((channel) => {
610608
if (!appearNote.channelId) return true;
611609
return channel.id !== appearNote.channelId;

packages/frontend/src/ui/deck/channel-column.vue

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { updateColumn, Column } from './deck-store.js';
2626
import MkTimeline from '@/components/MkTimeline.vue';
2727
import MkButton from '@/components/MkButton.vue';
2828
import * as os from '@/os.js';
29+
import { favoritedChannelsCache } from '@/cache.js';
2930
import { misskeyApi } from '@/scripts/misskey-api.js';
3031
import { i18n } from '@/i18n.js';
3132

@@ -42,20 +43,18 @@ if (props.column.channelId == null) {
4243
}
4344

4445
async function setChannel() {
45-
const channels = await misskeyApi('channels/my-favorites', {
46-
limit: 100,
47-
});
48-
const { canceled, result: channel } = await os.select({
46+
const channels = await favoritedChannelsCache.fetch();
47+
const { canceled, result: chosenChannel } = await os.select({
4948
title: i18n.ts.selectChannel,
5049
items: channels.map(x => ({
5150
value: x, text: x.name,
5251
})),
5352
default: props.column.channelId,
5453
});
55-
if (canceled) return;
54+
if (canceled || chosenChannel == null) return;
5655
updateColumn(props.column.id, {
57-
channelId: channel.id,
58-
name: channel.name,
56+
channelId: chosenChannel.id,
57+
name: chosenChannel.name,
5958
});
6059
}
6160

0 commit comments

Comments
 (0)