From 043f26c8951c1a980dd51cc1f31ab6c1ee69947d Mon Sep 17 00:00:00 2001 From: Marie Date: Thu, 21 Dec 2023 23:15:49 +0100 Subject: [PATCH] upd: improve performance for checking if instance is marked as NSFW on images --- .../core/activitypub/models/ApImageService.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index b7b8acd661..2eff7c64e0 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; -import type { DriveFilesRepository, InstancesRepository } from '@/models/_.js'; +import type { DriveFilesRepository } from '@/models/_.js'; import type { MiRemoteUser } from '@/models/User.js'; import type { MiDriveFile } from '@/models/DriveFile.js'; import { MetaService } from '@/core/MetaService.js'; @@ -15,10 +15,10 @@ import { DriveService } from '@/core/DriveService.js'; import type Logger from '@/logger.js'; import { bindThis } from '@/decorators.js'; import { checkHttps } from '@/misc/check-https.js'; +import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; import { ApResolverService } from '../ApResolverService.js'; import { ApLoggerService } from '../ApLoggerService.js'; import type { IObject } from '../type.js'; -import { UtilityService } from '@/core/UtilityService.js'; @Injectable() export class ApImageService { @@ -28,14 +28,11 @@ export class ApImageService { @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, - @Inject(DI.instancesRepository) - private instancesRepository: InstancesRepository, - private metaService: MetaService, private apResolverService: ApResolverService, private driveService: DriveService, private apLoggerService: ApLoggerService, - private utilityService: UtilityService, + private federatedInstanceService: FederatedInstanceService, ) { this.logger = this.apLoggerService.logger; } @@ -73,11 +70,11 @@ export class ApImageService { // 2. or the image is not sensitive const shouldBeCached = instance.cacheRemoteFiles && (instance.cacheRemoteSensitiveFiles || !image.sensitive); - const shouldBeSensitive = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(actor.host), isNSFW: true }); - - if (shouldBeSensitive) { - image.sensitive = true; - } + await this.federatedInstanceService.fetch(actor.host).then(async i => { + if (i.isNSFW) { + image.sensitive = true; + } + }); const file = await this.driveService.uploadFromUrl({ url: image.url,