diff --git a/packages/backend/src/db/scylla.ts b/packages/backend/src/db/scylla.ts index 3527bca42c..75b68d63a6 100644 --- a/packages/backend/src/db/scylla.ts +++ b/packages/backend/src/db/scylla.ts @@ -11,6 +11,7 @@ import { LocalFollowingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -499,17 +500,23 @@ export async function filterMutedNote( return notes; } -export async function filterBlockedUser( +export async function filterBlockUser( notes: ScyllaNote[], user: { id: User["id"] }, - blockerIds?: User["id"][], + blockIds?: User["id"][], ): Promise { let ids: User["id"][]; - if (blockerIds) { - ids = blockerIds; + if (blockIds) { + ids = blockIds; } else { - ids = await UserBlockedCache.init(user.id).then((cache) => cache.getAll()); + const blocked = await UserBlockedCache.init(user.id).then((cache) => + cache.getAll(), + ); + const blocking = await UserBlockingCache.init(user.id).then((cache) => + cache.getAll(), + ); + ids = [...blocked, ...blocking]; } return notes.filter( diff --git a/packages/backend/src/misc/cache.ts b/packages/backend/src/misc/cache.ts index a8d4b56cdd..5c5bbacaac 100644 --- a/packages/backend/src/misc/cache.ts +++ b/packages/backend/src/misc/cache.ts @@ -414,6 +414,25 @@ export class InstanceMutingsCache extends SetCache { } } +export class UserBlockingCache extends SetCache { + private constructor(userId: string) { + const fetcher = () => + Blockings.find({ + select: ["blockeeId"], + where: { blockerId: userId }, + }).then((blocks) => blocks.map(({ blockeeId }) => blockeeId)); + + super("blocking", userId, fetcher); + } + + public static async init(userId: string): Promise { + const cache = new UserBlockingCache(userId); + await cache.fetch(); + + return cache; + } +} + export class UserBlockedCache extends SetCache { private constructor(userId: string) { const fetcher = () => diff --git a/packages/backend/src/server/api/endpoints/blocking/create.ts b/packages/backend/src/server/api/endpoints/blocking/create.ts index 4984866470..f928543076 100644 --- a/packages/backend/src/server/api/endpoints/blocking/create.ts +++ b/packages/backend/src/server/api/endpoints/blocking/create.ts @@ -4,7 +4,7 @@ import { ApiError } from "../../error.js"; import { getUser } from "../../common/getters.js"; import { NoteWatchings, Users } from "@/models/index.js"; import { HOUR } from "@/const.js"; -import { UserBlockedCache } from "@/misc/cache.js"; +import { UserBlockingCache } from "@/misc/cache.js"; export const meta = { tags: ["account"], @@ -70,8 +70,9 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check if already blocking - const cache = await UserBlockedCache.init(blockee.id); - const exist = await cache.has(blocker.id); + const exist = await UserBlockingCache.init(blocker.id).then((cache) => + cache.has(blockee.id), + ); if (exist) { throw new ApiError(meta.errors.alreadyBlocking); diff --git a/packages/backend/src/server/api/endpoints/blocking/delete.ts b/packages/backend/src/server/api/endpoints/blocking/delete.ts index 9e69367305..09422e2650 100644 --- a/packages/backend/src/server/api/endpoints/blocking/delete.ts +++ b/packages/backend/src/server/api/endpoints/blocking/delete.ts @@ -4,7 +4,7 @@ import { ApiError } from "../../error.js"; import { getUser } from "../../common/getters.js"; import { Blockings, Users } from "@/models/index.js"; import { HOUR } from "@/const.js"; -import { UserBlockedCache } from "@/misc/cache.js"; +import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js"; export const meta = { tags: ["account"], @@ -70,8 +70,9 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check not blocking - const cache = await UserBlockedCache.init(blockee.id); - const exist = await cache.has(blocker.id); + const exist = await UserBlockingCache.init(blocker.id).then((cache) => + cache.has(blockee.id), + ); if (!exist) { throw new ApiError(meta.errors.notBlocking); diff --git a/packages/backend/src/server/api/endpoints/notes/children.ts b/packages/backend/src/server/api/endpoints/notes/children.ts index 9989154e24..936e310644 100644 --- a/packages/backend/src/server/api/endpoints/notes/children.ts +++ b/packages/backend/src/server/api/endpoints/notes/children.ts @@ -6,7 +6,7 @@ import { generateMutedUserQuery } from "../../common/generate-muted-user-query.j import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { ScyllaNote, - filterBlockedUser, + filterBlockUser, filterMutedNote, filterMutedUser, filterVisibility, @@ -20,6 +20,7 @@ import { InstanceMutingsCache, LocalFollowingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -63,24 +64,32 @@ export default define(meta, paramDef, async (ps, user) => { mutedUserIds, mutedInstances, blockerIds, + blockingIds, ]: string[][] = []; let mutedWords: string[][] = []; if (user) { - [followingUserIds, mutedUserIds, mutedInstances, mutedWords, blockerIds] = - await Promise.all([ - LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), - UserMutingsCache.init(user.id).then((cache) => cache.getAll()), - InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), - userWordMuteCache - .fetchMaybe(user.id, () => - UserProfiles.findOne({ - select: ["mutedWords"], - where: { userId: user.id }, - }).then((profile) => profile?.mutedWords), - ) - .then((words) => words ?? []), - UserBlockedCache.init(user.id).then((cache) => cache.getAll()), - ]); + [ + followingUserIds, + mutedUserIds, + mutedInstances, + mutedWords, + blockerIds, + blockingIds, + ] = await Promise.all([ + LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), + UserMutingsCache.init(user.id).then((cache) => cache.getAll()), + InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), + userWordMuteCache + .fetchMaybe(user.id, () => + UserProfiles.findOne({ + select: ["mutedWords"], + where: { userId: user.id }, + }).then((profile) => profile?.mutedWords), + ) + .then((words) => words ?? []), + UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), + ]); } const root = await getNote(ps.noteId, user, followingUserIds).catch( @@ -100,7 +109,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); } return filtered; }; diff --git a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts index 9ac54aa5a7..8384cf3ac1 100644 --- a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts @@ -12,7 +12,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterMutedNote, filterMutedRenotes, filterMutedUser, @@ -23,6 +23,7 @@ import { InstanceMutingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -94,25 +95,37 @@ export default define(meta, paramDef, async (ps, user) => { }); if (scyllaClient) { - let [mutedUserIds, mutedInstances, blockerIds, renoteMutedIds]: string[][] = - []; + let [ + mutedUserIds, + mutedInstances, + blockerIds, + blockingIds, + renoteMutedIds, + ]: string[][] = []; let mutedWords: string[][]; if (user) { - [mutedUserIds, mutedInstances, mutedWords, blockerIds, renoteMutedIds] = - await Promise.all([ - UserMutingsCache.init(user.id).then((cache) => cache.getAll()), - InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), - userWordMuteCache - .fetchMaybe(user.id, () => - UserProfiles.findOne({ - select: ["mutedWords"], - where: { userId: user.id }, - }).then((profile) => profile?.mutedWords), - ) - .then((words) => words ?? []), - UserBlockedCache.init(user.id).then((cache) => cache.getAll()), - RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), - ]); + [ + mutedUserIds, + mutedInstances, + mutedWords, + blockerIds, + blockingIds, + renoteMutedIds, + ] = await Promise.all([ + UserMutingsCache.init(user.id).then((cache) => cache.getAll()), + InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), + userWordMuteCache + .fetchMaybe(user.id, () => + UserProfiles.findOne({ + select: ["mutedWords"], + where: { userId: user.id }, + }).then((profile) => profile?.mutedWords), + ) + .then((words) => words ?? []), + UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), + RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), + ]); } const filter = async (notes: ScyllaNote[]) => { @@ -128,7 +141,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); } if (ps.withFiles) { @@ -140,10 +156,9 @@ export default define(meta, paramDef, async (ps, user) => { const foundPacked = []; while (foundPacked.length < ps.limit) { - const foundNotes = (await execNotePaginationQuery("global", ps, filter)).slice( - 0, - ps.limit * 1.5, - ); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. + const foundNotes = ( + await execNotePaginationQuery("global", ps, filter) + ).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. foundPacked.push( ...(await Notes.packMany(foundNotes, user, { scyllaNote: true })), ); diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index ce51d3fe6d..2f7129dcf4 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterChannel, filterMutedNote, filterMutedRenotes, @@ -30,6 +30,7 @@ import { LocalFollowingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -108,6 +109,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, mutedWords, blockerIds, + blockingIds, renoteMutedIds, ] = await Promise.all([ ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), @@ -123,6 +125,7 @@ export default define(meta, paramDef, async (ps, user) => { ) .then((words) => words ?? []), UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), ]); const homeUserIds = [user.id, ...followingUserIds]; @@ -145,7 +148,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); if (!ps.includeMyRenotes) { filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n)); diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts index 9bdc8ff7d4..00d0cded1d 100644 --- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts @@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterChannel, filterMutedNote, filterMutedRenotes, @@ -30,6 +30,7 @@ import { LocalFollowingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -115,6 +116,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedUserIds, mutedInstances, blockerIds, + blockingIds, renoteMutedIds, ]: string[][] = []; let mutedWords: string[][]; @@ -126,6 +128,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, mutedWords, blockerIds, + blockingIds, renoteMutedIds, ] = await Promise.all([ ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), @@ -141,6 +144,7 @@ export default define(meta, paramDef, async (ps, user) => { ) .then((words) => words ?? []), UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), ]); } @@ -157,7 +161,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); } if (ps.withFiles) { @@ -179,10 +186,9 @@ export default define(meta, paramDef, async (ps, user) => { const foundPacked = []; while (foundPacked.length < ps.limit) { - const foundNotes = (await execNotePaginationQuery("local", ps, filter)).slice( - 0, - ps.limit * 1.5, - ); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. + const foundNotes = ( + await execNotePaginationQuery("local", ps, filter) + ).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. foundPacked.push( ...(await Notes.packMany(foundNotes, user, { scyllaNote: true })), ); diff --git a/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts b/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts index 423f14fccc..3f7037138c 100644 --- a/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts @@ -15,7 +15,7 @@ import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-mu import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterMutedNote, filterMutedRenotes, filterMutedUser, @@ -28,6 +28,7 @@ import { LocalFollowingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -111,6 +112,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedUserIds, mutedInstances, blockerIds, + blockingIds, renoteMutedIds, ]: string[][] = []; let mutedWords: string[][]; @@ -121,6 +123,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, mutedWords, blockerIds, + blockingIds, renoteMutedIds, ] = await Promise.all([ LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), @@ -135,6 +138,7 @@ export default define(meta, paramDef, async (ps, user) => { ) .then((words) => words ?? []), UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), ]); } @@ -157,7 +161,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); } if (ps.withFiles) { diff --git a/packages/backend/src/server/api/endpoints/notes/renotes.ts b/packages/backend/src/server/api/endpoints/notes/renotes.ts index fe0e7bfea5..5a1dce6439 100644 --- a/packages/backend/src/server/api/endpoints/notes/renotes.ts +++ b/packages/backend/src/server/api/endpoints/notes/renotes.ts @@ -9,7 +9,7 @@ import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterMutedUser, filterVisibility, scyllaClient, @@ -18,6 +18,7 @@ import { InstanceMutingsCache, LocalFollowingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, } from "@/misc/cache.js"; @@ -75,13 +76,16 @@ export default define(meta, paramDef, async (ps, user) => { }); if (scyllaClient) { - let [mutedUserIds, mutedInstances, blockerIds]: string[][] = []; + let [mutedUserIds, mutedInstances, blockerIds, blockingIds]: string[][] = + []; if (user) { - [mutedUserIds, mutedInstances, blockerIds] = await Promise.all([ - UserMutingsCache.init(user.id).then((cache) => cache.getAll()), - InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), - UserBlockedCache.init(user.id).then((cache) => cache.getAll()), - ]); + [mutedUserIds, mutedInstances, blockerIds, blockingIds] = + await Promise.all([ + UserMutingsCache.init(user.id).then((cache) => cache.getAll()), + InstanceMutingsCache.init(user.id).then((cache) => cache.getAll()), + UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), + ]); } const filter = async (notes: ScyllaNote[]) => { @@ -97,7 +101,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedUserIds, mutedInstances, ); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); } return filtered; }; diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index f898ea1040..2a2977ef3b 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -20,7 +20,7 @@ import { execNotePaginationQuery, filterMutedUser, filterMutedNote, - filterBlockedUser, + filterBlockUser, filterMutedRenotes, } from "@/db/scylla.js"; import { @@ -29,6 +29,7 @@ import { LocalFollowingsCache, RenoteMutingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -99,6 +100,7 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, mutedWords, blockerIds, + blockingIds, renoteMutedIds, ] = await Promise.all([ ChannelFollowingsCache.init(user.id).then((cache) => cache.getAll()), @@ -114,6 +116,7 @@ export default define(meta, paramDef, async (ps, user) => { ) .then((words) => words ?? []), UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), RenoteMutingsCache.init(user.id).then((cache) => cache.getAll()), ]); const validUserIds = [user.id, ...followingUserIds]; @@ -132,7 +135,10 @@ export default define(meta, paramDef, async (ps, user) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); filtered = await filterMutedRenotes(filtered, user, renoteMutedIds); if (!ps.includeMyRenotes) { filtered = filtered.filter((n) => n.userId !== user.id || optFilter(n)); diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index 4420eea788..bd960c5ae4 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -10,7 +10,7 @@ import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { ScyllaNote, execNotePaginationQuery, - filterBlockedUser, + filterBlockUser, filterMutedNote, filterMutedUser, filterVisibility, @@ -20,6 +20,7 @@ import { InstanceMutingsCache, LocalFollowingsCache, UserBlockedCache, + UserBlockingCache, UserMutingsCache, userWordMuteCache, } from "@/misc/cache.js"; @@ -89,6 +90,7 @@ export default define(meta, paramDef, async (ps, me) => { mutedInstances, mutedWords, blockerIds, + blockingIds, ] = await Promise.all([ LocalFollowingsCache.init(user.id).then((cache) => cache.getAll()), UserMutingsCache.init(user.id).then((cache) => cache.getAll()), @@ -102,6 +104,7 @@ export default define(meta, paramDef, async (ps, me) => { ) .then((words) => words ?? []), UserBlockedCache.init(user.id).then((cache) => cache.getAll()), + UserBlockingCache.init(user.id).then((cache) => cache.getAll()), ]); if ( @@ -122,7 +125,10 @@ export default define(meta, paramDef, async (ps, me) => { mutedInstances, ); filtered = await filterMutedNote(filtered, user, mutedWords); - filtered = await filterBlockedUser(filtered, user, blockerIds); + filtered = await filterBlockUser(filtered, user, [ + ...blockerIds, + ...blockingIds, + ]); if (ps.withFiles) { filtered = filtered.filter((n) => n.files.length > 0); } diff --git a/packages/backend/src/services/blocking/create.ts b/packages/backend/src/services/blocking/create.ts index 6bf5587f93..32985880ae 100644 --- a/packages/backend/src/services/blocking/create.ts +++ b/packages/backend/src/services/blocking/create.ts @@ -19,7 +19,7 @@ import { perUserFollowingChart } from "@/services/chart/index.js"; import { genId } from "@/misc/gen-id.js"; import { getActiveWebhooks } from "@/misc/webhook-cache.js"; import { webhookDeliver } from "@/queue/index.js"; -import { UserBlockedCache } from "@/misc/cache.js"; +import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js"; export default async function (blocker: User, blockee: User) { await Promise.all([ @@ -41,8 +41,12 @@ export default async function (blocker: User, blockee: User) { await Blockings.insert(blocking); - const cache = await UserBlockedCache.init(blockee.id); - await cache.add(blocker.id); + await UserBlockedCache.init(blockee.id).then((cache) => + cache.add(blocker.id), + ); + await UserBlockingCache.init(blocker.id).then((cache) => + cache.add(blockee.id), + ); if (Users.isLocalUser(blocker) && Users.isRemoteUser(blockee)) { const content = renderActivity(renderBlock(blocking)); diff --git a/packages/backend/src/services/blocking/delete.ts b/packages/backend/src/services/blocking/delete.ts index 99666312cd..4f6c654a09 100644 --- a/packages/backend/src/services/blocking/delete.ts +++ b/packages/backend/src/services/blocking/delete.ts @@ -5,7 +5,7 @@ import { deliver } from "@/queue/index.js"; import Logger from "../logger.js"; import type { CacheableUser } from "@/models/entities/user.js"; import { Blockings, Users } from "@/models/index.js"; -import { UserBlockedCache } from "@/misc/cache.js"; +import { UserBlockedCache, UserBlockingCache } from "@/misc/cache.js"; const logger = new Logger("blocking/delete"); @@ -15,8 +15,12 @@ export default async function (blocker: CacheableUser, blockee: CacheableUser) { blockeeId: blockee.id, }); - const cache = await UserBlockedCache.init(blockee.id); - await cache.delete(blocker.id); + await UserBlockedCache.init(blockee.id).then((cache) => + cache.delete(blocker.id), + ); + await UserBlockingCache.init(blocker.id).then((cache) => + cache.delete(blockee.id), + ); if (blocking == null) { logger.warn(