From e265b538cc96b10b2ffc98c15227ab097cf4744b Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 17 Apr 2019 02:11:22 +0900 Subject: [PATCH] Fix #4724 --- src/models/entities/note.ts | 2 ++ src/services/drive/delete-file.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/models/entities/note.ts b/src/models/entities/note.ts index 969363da3..280f3dfcb 100644 --- a/src/models/entities/note.ts +++ b/src/models/entities/note.ts @@ -129,12 +129,14 @@ export class Note { }) public score: number; + @Index() @Column({ ...id(), array: true, default: '{}' }) public fileIds: DriveFile['id'][]; + @Index() @Column('varchar', { length: 256, array: true, default: '{}' }) diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts index bba453b98..1aba0d5fd 100644 --- a/src/services/drive/delete-file.ts +++ b/src/services/drive/delete-file.ts @@ -2,7 +2,7 @@ import * as Minio from 'minio'; import config from '../../config'; import { DriveFile } from '../../models/entities/drive-file'; import { InternalStorage } from './internal-storage'; -import { DriveFiles, Instances } from '../../models'; +import { DriveFiles, Instances, Notes } from '../../models'; import { driveChart, perUserDriveChart, instanceChart } from '../chart'; export default async function(file: DriveFile, isExpired = false) { @@ -40,6 +40,11 @@ export default async function(file: DriveFile, isExpired = false) { }); } else { DriveFiles.delete(file.id); + + // TODO: トランザクション + Notes.createQueryBuilder('note').delete() + .andWhere(':id = ANY(note.fileIds)', { id: file.id }) + .execute(); } // 統計を更新