From e2a8f4f88091554bc0fca8ec67f38673ffa1c822 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 27 Feb 2024 02:15:49 +0000 Subject: [PATCH] refresh --- .../src/core/activitypub/ApDbResolverService.ts | 12 +++++++++++- .../src/queue/processors/InboxProcessorService.ts | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts index 273572e0da..904c89b990 100644 --- a/packages/backend/src/core/activitypub/ApDbResolverService.ts +++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; -import type { NotesRepository, UserPublickeysRepository, UsersRepository } from '@/models/_.js'; +import type { MiUser, NotesRepository, UserPublickeysRepository, UsersRepository } from '@/models/_.js'; import type { Config } from '@/config.js'; import { MemoryKVCache } from '@/misc/cache.js'; import type { MiUserPublickey } from '@/models/UserPublickey.js'; @@ -190,6 +190,16 @@ export class ApDbResolverService implements OnApplicationShutdown { }; } + @bindThis + public refreshCacheByUserId(userId: MiUser['id']): void { + this.publicKeyByUserIdCache.delete(userId); + for (const [k, v] of this.publicKeyCache.cache.entries()) { + if (v.value?.userId === userId) { + this.publicKeyCache.delete(k); + } + } + } + @bindThis public dispose(): void { this.publicKeyCache.dispose(); diff --git a/packages/backend/src/queue/processors/InboxProcessorService.ts b/packages/backend/src/queue/processors/InboxProcessorService.ts index 0a713149e5..bc593147bb 100644 --- a/packages/backend/src/queue/processors/InboxProcessorService.ts +++ b/packages/backend/src/queue/processors/InboxProcessorService.ts @@ -119,7 +119,8 @@ export class InboxProcessorService { // みたいになっててUserを引っ張れば公開キーも入ることを期待する if (activity.signature.creator) { const candicate = activity.signature.creator.replace(/#.*/, ''); - await this.apPersonService.resolvePerson(candicate).catch(() => null); + const user = await this.apPersonService.resolvePerson(candicate).catch(() => null); + if (user) this.apDbResolverService.refreshCacheByUserId(user.id); } // keyIdからLD-Signatureのユーザーを取得