1
1
import { Injectable } from '@nestjs/common' ;
2
- import { Insertable , Kysely , Updateable } from 'kysely' ;
2
+ import { Insertable , Kysely , sql , Updateable } from 'kysely' ;
3
3
import { jsonArrayFrom } from 'kysely/helpers/postgres' ;
4
4
import { DateTime } from 'luxon' ;
5
5
import { InjectKysely } from 'nestjs-kysely' ;
6
6
import { DB , Memories } from 'src/db' ;
7
7
import { Chunked , ChunkedSet , DummyValue , GenerateSql } from 'src/decorators' ;
8
8
import { MemorySearchDto } from 'src/dtos/memory.dto' ;
9
+ import { AssetVisibility } from 'src/enum' ;
9
10
import { IBulkAsset } from 'src/types' ;
10
11
11
12
@Injectable ( )
12
13
export class MemoryRepository implements IBulkAsset {
13
14
constructor ( @InjectKysely ( ) private db : Kysely < DB > ) { }
14
15
15
- cleanup ( ) {
16
+ async cleanup ( ) {
17
+ await this . db
18
+ . deleteFrom ( 'memories_assets_assets' )
19
+ . using ( 'assets' )
20
+ . whereRef ( 'memories_assets_assets.assetsId' , '=' , 'assets.id' )
21
+ . where ( 'assets.visibility' , '!=' , AssetVisibility . TIMELINE )
22
+ . execute ( ) ;
23
+
16
24
return this . db
17
25
. deleteFrom ( 'memories' )
18
26
. where ( 'createdAt' , '<' , DateTime . now ( ) . minus ( { days : 30 } ) . toJSDate ( ) )
@@ -36,6 +44,7 @@ export class MemoryRepository implements IBulkAsset {
36
44
. innerJoin ( 'memories_assets_assets' , 'assets.id' , 'memories_assets_assets.assetsId' )
37
45
. whereRef ( 'memories_assets_assets.memoriesId' , '=' , 'memories.id' )
38
46
. orderBy ( 'assets.fileCreatedAt' , 'asc' )
47
+ . where ( 'assets.visibility' , '=' , sql . lit ( AssetVisibility . TIMELINE ) )
39
48
. where ( 'assets.deletedAt' , 'is' , null ) ,
40
49
) . as ( 'assets' ) ,
41
50
)
@@ -138,6 +147,7 @@ export class MemoryRepository implements IBulkAsset {
138
147
. innerJoin ( 'memories_assets_assets' , 'assets.id' , 'memories_assets_assets.assetsId' )
139
148
. whereRef ( 'memories_assets_assets.memoriesId' , '=' , 'memories.id' )
140
149
. orderBy ( 'assets.fileCreatedAt' , 'asc' )
150
+ . where ( 'assets.visibility' , '=' , sql . lit ( AssetVisibility . TIMELINE ) )
141
151
. where ( 'assets.deletedAt' , 'is' , null ) ,
142
152
) . as ( 'assets' ) ,
143
153
)
0 commit comments