From 307e1c4d96e7c2816e62790889d1144e81f0a618 Mon Sep 17 00:00:00 2001
From: tamaina <tamaina@hotmail.co.jp>
Date: Sat, 20 Jul 2024 23:50:56 +0900
Subject: [PATCH] =?UTF-8?q?short=20cache=20ttl=2012min=20=E2=86=92=205min?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../backend/src/core/activitypub/ApDbResolverService.ts     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts
index 973394683f..2ae76e5aac 100644
--- a/packages/backend/src/core/activitypub/ApDbResolverService.ts
+++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts
@@ -14,11 +14,11 @@ import type { MiNote } from '@/models/Note.js';
 import { bindThis } from '@/decorators.js';
 import { MiLocalUser, MiRemoteUser } from '@/models/User.js';
 import Logger from '@/logger.js';
+import { UtilityService } from '../UtilityService.js';
 import { getApId } from './type.js';
 import { ApPersonService } from './models/ApPersonService.js';
 import { ApLoggerService } from './ApLoggerService.js';
 import type { IObject } from './type.js';
-import { UtilityService } from '../UtilityService.js';
 
 export type UriParseResult = {
 	/** wether the URI was generated by us */
@@ -225,7 +225,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
 		 * If not found with keyId, update cache and reacquire
 		 */
 		const cacheRaw = this.publicKeyByUserIdCache.cache.get(user.id);
-		if (cacheRaw && cacheRaw.date > Date.now() - 1000 * 60 * 12) {
+		if (cacheRaw && Date.now() - cacheRaw.date > 1000 * 60 * 5) {
 			const exactKey = await this.refreshAndFindKey(user.id, keyId);
 			if (exactKey) return { user, key: exactKey };
 		}
@@ -234,7 +234,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
 		 * lastFetchedAtでの更新制限を弱めて再取得
 		 * Reacquisition with weakened update limit at lastFetchedAt
 		 */
-		if (user.lastFetchedAt == null || user.lastFetchedAt < new Date(Date.now() - 1000 * 60 * 12)) {
+		if (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 5) {
 			this.logger.info(`Fetching user to find public key uri=${uri} userId=${user.id} keyId=${keyId}`);
 			const renewed = await this.apPersonService.fetchPersonWithRenewal(uri, 0);
 			if (renewed == null || renewed.isDeleted) return null;