File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/components/file/media Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { FileVersion } from '../dto';
6
6
import { FileRepository } from '../file.repository' ;
7
7
import { MediaService } from './media.service' ;
8
8
9
- @Migration ( '2023-09-01T18 :00:00' )
9
+ @Migration ( '2023-09-05T19 :00:00' )
10
10
export class DetectExistingMediaMigration extends BaseMigration {
11
11
constructor (
12
12
private readonly mediaService : MediaService ,
@@ -16,8 +16,9 @@ export class DetectExistingMediaMigration extends BaseMigration {
16
16
}
17
17
18
18
async up ( ) {
19
+ await this . dropAllDuplicatedMedia ( ) ;
20
+
19
21
const detect = async ( f : FileVersion ) => {
20
- this . logger . info ( 'Detecting' , f ) ;
21
22
try {
22
23
const result = await this . mediaService . detectAndSave ( f ) ;
23
24
this . logger . info ( 'Detected and saved media' , {
@@ -80,4 +81,14 @@ export class DetectExistingMediaMigration extends BaseMigration {
80
81
// eslint-disable-next-line no-constant-condition
81
82
} while ( true ) ;
82
83
}
84
+
85
+ private async dropAllDuplicatedMedia ( ) {
86
+ await this . db . query ( ) . raw `
87
+ match (fv:FileVersion)-->(media:Media)
88
+ with fv, collect(media) as medias
89
+ where size(medias) > 1
90
+ unwind medias as media
91
+ detach delete media
92
+ ` . executeAndLogStats ( ) ;
93
+ }
83
94
}
You can’t perform that action at this time.
0 commit comments