fix: cache muted words

This commit is contained in:
naskya 2023-10-17 07:55:07 +09:00
parent ae637ec85b
commit bdf3311402
No known key found for this signature in database
GPG Key ID: 164DFF24E2D40139

View File

@ -9,6 +9,7 @@ import { Cache } from "./cache.js";
import { getWordHardMute } from "./check-word-mute.js"; import { getWordHardMute } from "./check-word-mute.js";
const blockingCache = new Cache<User["id"][]>("blocking", 60 * 5); const blockingCache = new Cache<User["id"][]>("blocking", 60 * 5);
const mutedWordsCache = new Cache<string[][] | undefined>("mutedWords", 60 * 5);
export async function checkHitAntenna( export async function checkHitAntenna(
antenna: Antenna, antenna: Antenna,
@ -22,14 +23,6 @@ export async function checkHitAntenna(
if (note.fileIds && note.fileIds.length === 0) return false; 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") { if (antenna.src === "users") {
const accts = antenna.users.map((x) => { const accts = antenna.users.map((x) => {
const { username, host } = Acct.parse(x); const { username, host } = Acct.parse(x);
@ -88,16 +81,20 @@ export async function checkHitAntenna(
if (matched) return false; if (matched) return false;
} }
if ( // アンテナ作成者がノート作成者にブロックされていたらスキップ
await getWordHardMute( const blockings = await blockingCache.fetch(noteUser.id, () =>
note, Blockings.findBy({ blockerId: noteUser.id }).then((res) =>
antenna.userId, res.map((x) => x.blockeeId),
( ),
await UserProfiles.findOneBy({ userId: antenna.userId }) );
)?.mutedWords, if (blockings.includes(antenna.userId)) return false;
)
) const mutedWords = await mutedWordsCache.fetch(antenna.userId, () =>
return false; UserProfiles.findOneBy({ userId: antenna.userId }).then(
(profile) => profile?.mutedWords,
),
);
if (await getWordHardMute(note, antenna.userId, mutedWords)) return false;
// TODO: eval expression // TODO: eval expression