Skip to content

Commit

Permalink
Fix: Opensearch利用時ファイルのセンシティブ状態が変更されたとき変更されるように (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
penginn-net authored Oct 17, 2024
1 parent 7abb4ab commit 2d9ccd3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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利用時)高度な検索でリプライ除外にするとエラーがでる

Expand Down
35 changes: 35 additions & 0 deletions packages/backend/src/core/AdvancedSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -95,6 +97,7 @@ export class DriveService {
private registerLogger: Logger;
private downloaderLogger: Logger;
private deleteLogger: Logger;
private advancedSearchService: AdvancedSearchService;

constructor(
@Inject(DI.config)
Expand Down Expand Up @@ -131,13 +134,18 @@ 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');
this.downloaderLogger = logger.createSubLogger('downloader');
this.deleteLogger = logger.createSubLogger('delete');
}

onModuleInit() {
this.advancedSearchService = this.moduleRef.get('AdvancedSearchService');
}

/***
* Save file
* @param path Path for original
Expand Down Expand Up @@ -767,6 +775,7 @@ export class DriveService {
}
}
}
this.advancedSearchService.updateNoteSensitive(file.id);

return fileObj;
}
Expand Down

0 comments on commit 2d9ccd3

Please sign in to comment.