diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index e472acd38..ee6e90a66 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -1,7 +1,7 @@ export class Cache { - public cache: Map; + public cache: Map; private lifetime: number; - public fetcher: (key: string | null) => Promise; + public fetcher: (key: string) => Promise; constructor(lifetime: number, fetcher: Cache['fetcher']) { this.cache = new Map(); @@ -9,14 +9,14 @@ export class Cache { this.fetcher = fetcher; } - public set(key: string | null, value: T): void { + public set(key: string, value: T): void { this.cache.set(key, { date: Date.now(), value, }); } - public get(key: string | null): T | undefined { + public get(key: string): T | undefined { const cached = this.cache.get(key); if (cached == null) return undefined; @@ -29,7 +29,7 @@ export class Cache { return cached.value; } - public delete(key: string | null): void { + public delete(key: string): void { this.cache.delete(key); } @@ -38,7 +38,7 @@ export class Cache { * run to get the value. If the fetcher returns undefined, it is * returned but not cached. */ - public async fetch(key: string | null): Promise { + public async fetch(key: string): Promise { const cached = this.get(key); if (cached !== undefined) { return cached; diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index e7dac0886..77a6e4c47 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -266,7 +266,7 @@ export default async (user: { id: User['id']; username: User['username']; host: incNotesCountOfUser(user); // Word mute - mutedWordsCache.fetch(null).then(us => { + mutedWordsCache.fetch('').then(us => { for (const u of us) { checkWordMute(note, { id: u.userId }, u.mutedWords).then(shouldMute => { if (shouldMute) { diff --git a/packages/backend/src/services/relay.ts b/packages/backend/src/services/relay.ts index 725ce30ce..35779e79a 100644 --- a/packages/backend/src/services/relay.ts +++ b/packages/backend/src/services/relay.ts @@ -93,7 +93,7 @@ export async function relayRejected(id: string): Promise { export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise { if (activity == null) return; - const relays = await relaysCache.fetch(null); + const relays = await relaysCache.fetch(''); if (relays == null || relays.length === 0) return; // TODO diff --git a/packages/backend/src/services/user-cache.ts b/packages/backend/src/services/user-cache.ts index d67931c2c..2d2ec5711 100644 --- a/packages/backend/src/services/user-cache.ts +++ b/packages/backend/src/services/user-cache.ts @@ -6,15 +6,15 @@ import { subscriber } from '@/db/redis.js'; export const userByIdCache = new Cache( Infinity, - async (id) => id ? (await Users.findOneBy({ id }) ?? undefined) : undefined, + async (id) => await Users.findOneBy({ id }) ?? undefined, ); export const localUserByNativeTokenCache = new Cache( Infinity, - async (token) => token ? (await Users.findOneBy({ token, host: IsNull() }) as ILocalUser | null ?? undefined) : undefined, + async (token) => await Users.findOneBy({ token, host: IsNull() }) as ILocalUser | null ?? undefined, ); export const uriPersonCache = new Cache( Infinity, - async (uri) => uri ? (await Users.findOneBy({ uri }) ?? undefined) : undefined, + async (uri) => await Users.findOneBy({ uri }) ?? undefined, ); subscriber.on('message', async (_, data) => {