From 61ea5559436a945f389efc6fc50f6f20b6455ed5 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Fri, 14 Nov 2025 19:32:36 -0500 Subject: [PATCH] fix refetchPublicKeyForApId always proceeding even if the timeout fails --- .../src/core/activitypub/ApDbResolverService.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts index d9a8d545b7..a5259b1c4a 100644 --- a/packages/backend/src/core/activitypub/ApDbResolverService.ts +++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts @@ -129,20 +129,21 @@ export class ApDbResolverService implements OnApplicationShutdown { */ @bindThis public async refetchPublicKeyForApId(user: MiRemoteUser): Promise { + const oldKey = await this.apPersonService.findPublicKeyByUserId(user.id); + // Don't re-fetch if we've updated the user recently - if ( - (user.lastFetchedAt && user.lastFetchedAt.valueOf() > maxUpdatedTime) || const maxUpdatedTime = this.timeService.now - (1000 * 60 * 60); // 1 hour + if ((user.lastFetchedAt && user.lastFetchedAt.valueOf() > maxUpdatedTime) || (user.updatedAt && user.updatedAt.valueOf() > maxUpdatedTime) || this.idService.parse(user.id).date.valueOf() > maxUpdatedTime ) { this.apLoggerService.logger.debug(`Not updating public key for user ${user.id} (${user.uri}): already checked recently`); - } else { - this.apLoggerService.logger.debug(`Updating public key for user ${user.id} (${user.uri})`); + return oldKey; } - // findPublicKeyByUserId pulls from a cache, but updatePerson also updates that cache if there's any changes. - const oldKey = await this.apPersonService.findPublicKeyByUserId(user.id); + this.apLoggerService.logger.debug(`Updating public key for user ${user.id} (${user.uri})`); + + // updatePerson will update the public key cache if there's any changes. await this.apPersonService.updatePerson(user.uri); const newKey = await this.apPersonService.findPublicKeyByUserId(user.id);