@@ -197,10 +197,7 @@ async function handleProfileUpdate(manager: EntityManager, tx: BorkTxData) {
197
197
break
198
198
}
199
199
200
- await Promise . all ( [
201
- manager . update ( User , senderAddress , params ) ,
202
- createBork ( manager , tx ) ,
203
- ] )
200
+ await manager . update ( User , senderAddress , params )
204
201
}
205
202
206
203
async function createBork ( manager : EntityManager , tx : BorkTxData & { parentTxid ?: string } ) : Promise < void > {
@@ -250,10 +247,11 @@ async function handleCommentReborkLike (manager: EntityManager, tx: BorkTxData):
250
247
} )
251
248
if ( ! parent ) { return }
252
249
253
- // create bork if parent exists
250
+ // create bork if parent exists, no need to save recipient
254
251
await createBork ( manager , {
255
252
...tx ,
256
253
parentTxid : parent . txid ,
254
+ recipientAddress : null ,
257
255
} )
258
256
}
259
257
@@ -342,46 +340,39 @@ async function handleDelete (manager: EntityManager, tx: BorkTxData): Promise<vo
342
340
} )
343
341
if ( ! bork ) { return }
344
342
345
- let conditions : FindConditions < Bork > = { }
346
- let params : Partial < Bork > = { deletedAt : new Date ( time ) }
347
343
switch ( bork . type ) {
348
- // delete single bork if bork, comment, rebork, extension
344
+ // soft delete single bork if bork, comment, rebork, extension
349
345
case BorkType . Bork :
350
346
case BorkType . Comment :
351
347
case BorkType . Rebork :
352
348
case BorkType . Extension :
353
- conditions . txid = bork . txid
354
- params . content = null
349
+ await manager . update ( Bork , bork . txid , {
350
+ deletedAt : new Date ( time ) ,
351
+ content : null ,
352
+ } )
355
353
break
356
- // delete all if like, flag, follow, block
354
+ // hard delete all if like, flag, follow, block
357
355
case BorkType . Like :
358
356
case BorkType . Flag :
359
357
case BorkType . Follow :
360
358
case BorkType . Block :
361
- conditions . sender = { address : bork . senderAddress }
362
- conditions . type = bork . type
363
- conditions . deletedAt = IsNull ( )
359
+ const conditions : FindConditions < Bork > = {
360
+ sender : { address : bork . senderAddress } ,
361
+ type : bork . type ,
362
+ }
364
363
// find by parent if like, flag
365
364
if ( [ BorkType . Like , BorkType . Flag ] . includes ( bork . type ) ) {
366
365
conditions . parent = { txid : bork . parentTxid }
367
366
// find by recipient if follow, block
368
367
} else {
369
368
conditions . recipient = { address : bork . recipientAddress }
370
369
}
370
+ await manager . delete ( Bork , conditions )
371
371
break
372
372
// do nothing if setName, setBio, setAvatar, delete
373
373
default :
374
374
break
375
375
}
376
-
377
- await Promise . all ( [
378
- manager . update ( Bork , conditions , params ) ,
379
- createBork ( manager , {
380
- ...tx ,
381
- content : null ,
382
- parentTxid : bork . txid ,
383
- } ) ,
384
- ] )
385
376
}
386
377
387
378
async function cleanupOrphans ( ) : Promise < void > {
0 commit comments