@@ -17,27 +17,50 @@ export class PeriodicDbDeleter {
17
17
@inject ( TypeORM ) protected readonly typeORM : TypeORM ;
18
18
19
19
start ( ) {
20
- log . error ( "[PeriodicDbDeleter] Start ..." ) ;
20
+ log . info ( "[PeriodicDbDeleter] Start ..." ) ;
21
21
this . sync ( ) . catch ( ( err ) => log . error ( "[PeriodicDbDeleter] sync failed" , err ) ) ;
22
22
}
23
23
24
24
protected async sync ( ) {
25
25
const doSync = async ( ) => {
26
+ const tickID = new Date ( ) . toISOString ( ) ;
27
+ log . info ( "[PeriodicDbDeleter] Starting to collect deleted rows." , {
28
+ periodicDeleterTickId : tickID ,
29
+ } ) ;
26
30
const sortedTables = this . tableProvider . getSortedTables ( ) ;
27
31
const toBeDeleted : { table : string ; deletions : string [ ] } [ ] = [ ] ;
28
32
for ( const table of sortedTables ) {
29
- toBeDeleted . push ( await this . collectRowsToBeDeleted ( table ) ) ;
33
+ const rowsForTableToDelete = await this . collectRowsToBeDeleted ( table ) ;
34
+ log . info (
35
+ `[PeriodicDbDeleter] Identified ${ rowsForTableToDelete . deletions . length } entries in ${ rowsForTableToDelete . table } to be deleted.` ,
36
+ {
37
+ periodicDeleterTickId : tickID ,
38
+ } ,
39
+ ) ;
40
+ toBeDeleted . push ( rowsForTableToDelete ) ;
30
41
}
31
42
// when collecting the deletions do so in the inverse order as during update (delete dependency targes first)
32
43
const pendingDeletions : Promise < void > [ ] = [ ] ;
33
44
for ( const { deletions } of toBeDeleted . reverse ( ) ) {
34
45
for ( const deletion of deletions ) {
35
46
pendingDeletions . push (
36
- this . query ( deletion ) . catch ( ( err ) => log . error ( `[PeriodicDbDeleter] sync error` , err ) ) ,
47
+ this . query ( deletion ) . catch ( ( err ) =>
48
+ log . error (
49
+ `[PeriodicDbDeleter] sync error` ,
50
+ {
51
+ periodicDeleterTickId : tickID ,
52
+ query : deletion ,
53
+ } ,
54
+ err ,
55
+ ) ,
56
+ ) ,
37
57
) ;
38
58
}
39
59
}
40
60
await Promise . all ( pendingDeletions ) ;
61
+ log . info ( "[PeriodicDbDeleter] Finished deleting records." , {
62
+ periodicDeleterTickId : tickID ,
63
+ } ) ;
41
64
} ;
42
65
repeat ( doSync , 30000 ) ; // deletion is never time-critical, so we should ensure we do not spam ourselves
43
66
}
0 commit comments