From bdf3311402052e83c33cd16a1363b82db7a6708f Mon Sep 17 00:00:00 2001 From: naskya Date: Tue, 17 Oct 2023 07:55:07 +0900 Subject: [PATCH] fix: cache muted words --- .../backend/src/misc/check-hit-antenna.ts | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/backend/src/misc/check-hit-antenna.ts b/packages/backend/src/misc/check-hit-antenna.ts index 270a58cf1..199b2d964 100644 --- a/packages/backend/src/misc/check-hit-antenna.ts +++ b/packages/backend/src/misc/check-hit-antenna.ts @@ -9,6 +9,7 @@ import { Cache } from "./cache.js"; import { getWordHardMute } from "./check-word-mute.js"; const blockingCache = new Cache("blocking", 60 * 5); +const mutedWordsCache = new Cache("mutedWords", 60 * 5); export async function checkHitAntenna( antenna: Antenna, @@ -22,14 +23,6 @@ export async function checkHitAntenna( if (note.fileIds && note.fileIds.length === 0) return false; } - // アンテナ作成者がノート作成者にブロックされていたらスキップ - const blockings = await blockingCache.fetch(noteUser.id, () => - Blockings.findBy({ blockerId: noteUser.id }).then((res) => - res.map((x) => x.blockeeId), - ), - ); - if (blockings.some((blocking) => blocking === antenna.userId)) return false; - if (antenna.src === "users") { const accts = antenna.users.map((x) => { const { username, host } = Acct.parse(x); @@ -88,16 +81,20 @@ export async function checkHitAntenna( if (matched) return false; } - if ( - await getWordHardMute( - note, - antenna.userId, - ( - await UserProfiles.findOneBy({ userId: antenna.userId }) - )?.mutedWords, - ) - ) - return false; + // アンテナ作成者がノート作成者にブロックされていたらスキップ + const blockings = await blockingCache.fetch(noteUser.id, () => + Blockings.findBy({ blockerId: noteUser.id }).then((res) => + res.map((x) => x.blockeeId), + ), + ); + if (blockings.includes(antenna.userId)) return false; + + const mutedWords = await mutedWordsCache.fetch(antenna.userId, () => + UserProfiles.findOneBy({ userId: antenna.userId }).then( + (profile) => profile?.mutedWords, + ), + ); + if (await getWordHardMute(note, antenna.userId, mutedWords)) return false; // TODO: eval expression