From d7c32cef70133179039695d2b5feb6a77856bddb Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 10 Mar 2024 16:38:53 +0000 Subject: [PATCH] =?UTF-8?q?fetchPersonWithRenewal=E3=81=A7=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E8=B5=B7=E3=81=8D=E3=81=9F=E3=82=89?= =?UTF-8?q?=E5=8F=A4=E3=81=84=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E8=BF=94?= =?UTF-8?q?=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/activitypub/models/ApPersonService.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 1b01b9e2a9..545a8af4ec 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -249,6 +249,12 @@ export class ApPersonService implements OnModuleInit { return null; } + /** + * uriからUser(Person)をフェッチします。 + * + * Misskeyに対象のPersonが登録されていればそれを返し、登録がなければnullを返します。 + * また、TTLが0でない場合、TTLを過ぎていた場合はupdatePersonを実行します。 + */ @bindThis async fetchPersonWithRenewal(uri: string, TTL = REMOTE_USER_CACHE_TTL): Promise { const exist = await this.fetchPerson(uri); @@ -257,8 +263,12 @@ export class ApPersonService implements OnModuleInit { if (this.userEntityService.isRemoteUser(exist)) { if (TTL === 0 || exist.lastFetchedAt == null || Date.now() - exist.lastFetchedAt.getTime() > TTL) { this.logger.debug('fetchPersonWithRenewal: renew', { uri, TTL, lastFetchedAt: exist.lastFetchedAt }); - await this.updatePerson(exist.uri); - return await this.fetchPerson(uri); + try { + await this.updatePerson(exist.uri); + return await this.fetchPerson(uri); + } catch (err) { + this.logger.error('error occurred while renewing user', { err }); + } } this.logger.debug('fetchPersonWithRenewal: use cache', { uri, TTL, lastFetchedAt: exist.lastFetchedAt }); }