diff --git a/CHANGELOG_YOJO.md b/CHANGELOG_YOJO.md index bd44bb9c0f..44991a5a27 100644 --- a/CHANGELOG_YOJO.md +++ b/CHANGELOG_YOJO.md @@ -39,6 +39,7 @@ Cherrypick 4.11.1 ### Server - Enhance: リモートユーザーの`/api/clips/show`と`/api/users/clips`の応答にemojisを追加 [#466](https://github.com/yojo-art/cherrypick/pull/466) +- Fix: Opensearch利用時ファイルのセンシティブ状態が変更されたとき変更されるように - Change: `notes/advanced-search`で`query`が必須ではなくなりました - Fix: (Opensearch利用時)高度な検索でリプライ除外にするとエラーがでる diff --git a/packages/backend/src/core/AdvancedSearchService.ts b/packages/backend/src/core/AdvancedSearchService.ts index d831fd9dc6..47ff20be1a 100644 --- a/packages/backend/src/core/AdvancedSearchService.ts +++ b/packages/backend/src/core/AdvancedSearchService.ts @@ -367,6 +367,41 @@ export class AdvancedSearchService { this.index(this.opensearchNoteIndex as string, note.id, body); } + @bindThis + public async updateNoteSensitive(fileId: string) { + if (!this.opensearch) return; + + const limit = 100; + let latestid = undefined; + + while (true) { + const notes = await this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), latestid, undefined) + .andWhere(':file <@ note.fileIds', { file: [fileId] }) + .limit(limit) + .getMany(); + + if (notes.length === 0 ) break; + + notes.forEach((note) => { + this.driveService.getSensitiveFileCount(note.fileIds) + .then((sensitiveCount) => { + const nonSensitiveCount = note.fileIds.length - sensitiveCount; + const body = { + fileIds: note.fileIds, + sensitiveFileCount: sensitiveCount, + nonSensitiveFileCount: nonSensitiveCount, + }; + this.opensearch?.update({ + id: note.id, + index: this.opensearchNoteIndex as string, + body: { doc: body }, + }); + }); + latestid = note.id; + }); + } + } + @bindThis private async index(index: string, id: string, body: any ) { if (!this.opensearch) return; diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index 4ad4627024..656791fdf3 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -6,6 +6,7 @@ import { randomUUID } from 'node:crypto'; import * as fs from 'node:fs'; import { Inject, Injectable } from '@nestjs/common'; +import { ModuleRef } from '@nestjs/core'; import sharp from 'sharp'; import { sharpBmp } from '@misskey-dev/sharp-read-bmp'; import { IsNull } from 'typeorm'; @@ -45,6 +46,7 @@ import { isMimeImage } from '@/misc/is-mime-image.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { UtilityService } from '@/core/UtilityService.js'; import { RegistryApiService } from '@/core/RegistryApiService.js'; +import { AdvancedSearchService } from './AdvancedSearchService.js'; type AddFileArgs = { /** User who wish to add file */ @@ -95,6 +97,7 @@ export class DriveService { private registerLogger: Logger; private downloaderLogger: Logger; private deleteLogger: Logger; + private advancedSearchService: AdvancedSearchService; constructor( @Inject(DI.config) @@ -131,6 +134,7 @@ export class DriveService { private instanceChart: InstanceChart, private utilityService: UtilityService, private registryApiService: RegistryApiService, + private moduleRef: ModuleRef, ) { const logger = new Logger('drive', 'blue'); this.registerLogger = logger.createSubLogger('register', 'yellow'); @@ -138,6 +142,10 @@ export class DriveService { this.deleteLogger = logger.createSubLogger('delete'); } + onModuleInit() { + this.advancedSearchService = this.moduleRef.get('AdvancedSearchService'); + } + /*** * Save file * @param path Path for original @@ -767,6 +775,7 @@ export class DriveService { } } } + this.advancedSearchService.updateNoteSensitive(file.id); return fileObj; }