From 5e802df4c95366d385c13de8ad0fb20bdde3bdd1 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Tue, 5 Sep 2023 13:00:15 -0400 Subject: [PATCH] fix: update cache --- .../src/remote/activitypub/kernel/move/index.ts | 14 ++++++++++++++ .../backend/src/server/api/endpoints/i/move.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/backend/src/remote/activitypub/kernel/move/index.ts b/packages/backend/src/remote/activitypub/kernel/move/index.ts index 800fd7bfea..9b07d17228 100644 --- a/packages/backend/src/remote/activitypub/kernel/move/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/move/index.ts @@ -9,6 +9,7 @@ import deleteFollowing from "@/services/following/delete.js"; import type { IMove } from "../../type.js"; import { getApHrefNullable } from "../../type.js"; +import { userByIdCache, userDenormalizedCache } from "@/services/user-cache.js"; export default async ( actor: CacheableRemoteUser, @@ -45,6 +46,19 @@ export default async ( } // add target uri to movedToUri in order to indicate that the user has moved + await userByIdCache.get(old_acc.id).then((cached) => { + if (cached) { + userByIdCache.set(cached.id, { ...cached, movedToUri: targetUri }); + } + }); + await userDenormalizedCache.get(old_acc.id).then((cached) => { + if (cached) { + userDenormalizedCache.set(cached.id, { + ...cached, + movedToUri: targetUri, + }); + } + }); await Users.update(old_acc.id, { movedToUri: targetUri }); // follow the new account and unfollow the old one diff --git a/packages/backend/src/server/api/endpoints/i/move.ts b/packages/backend/src/server/api/endpoints/i/move.ts index d972aaf1d9..0cafcbc902 100644 --- a/packages/backend/src/server/api/endpoints/i/move.ts +++ b/packages/backend/src/server/api/endpoints/i/move.ts @@ -13,6 +13,7 @@ import { Followings, Users } from "@/models/index.js"; import config from "@/config/index.js"; import { publishMainStream } from "@/services/stream.js"; import { parse } from "@/misc/acct.js"; +import { userByIdCache, userDenormalizedCache } from "@/services/user-cache.js"; export const meta = { tags: ["users"], @@ -127,7 +128,18 @@ export default define(meta, paramDef, async (ps, user) => { updates.movedToUri = toUrl; updates.alsoKnownAs = user.alsoKnownAs?.concat(toUrl) ?? [toUrl]; + await userByIdCache.get(user.id).then((cached) => { + if (cached) { + userByIdCache.set(cached.id, { ...cached, ...updates }); + } + }); + await userDenormalizedCache.get(user.id).then((cached) => { + if (cached) { + userDenormalizedCache.set(cached.id, { ...cached, ...updates }); + } + }); await Users.update(user.id, updates); + const iObj = await Users.pack(user.id, user, { detail: true, includeSecrets: true,