Skip to content

Commit 8f014ca

Browse files
author
MattDHill
committed
hard delete follow/blocks, no bork for profile updates
1 parent 18ead0b commit 8f014ca

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/api/handlers/bork.ts

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export class BorkHandler {
4848
qb.where('sender_address = :myAddress')
4949
.orWhere('recipient_address = :myAddress')
5050
}))
51-
.andWhere('deleted_at IS NULL')
5251
.getQuery()
5352
return `borks.sender_address NOT IN ${subQuery}`
5453
})
@@ -74,7 +73,6 @@ export class BorkHandler {
7473
.from(Bork, 'borks')
7574
.where('type = :followType', { followType: BorkType.Follow })
7675
.andWhere('sender_address = :myAddress')
77-
.andWhere('deleted_at IS NULL')
7876
.getQuery()
7977
return `borks.sender_address IN ${subQuery}`
8078
})

src/api/handlers/user.ts

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export class UserHandler {
151151
let subquery = qb.subQuery()
152152
.from(Bork, 'borks')
153153
.where('type = :type', { type: BorkType.Follow })
154-
.andWhere('deleted_at IS NULL')
155154

156155
if (type === 'following') {
157156
subquery.select('recipient_address')

src/scripts/sync.ts

+14-23
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ async function handleProfileUpdate(manager: EntityManager, tx: BorkTxData) {
197197
break
198198
}
199199

200-
await Promise.all([
201-
manager.update(User, senderAddress, params),
202-
createBork(manager, tx),
203-
])
200+
await manager.update(User, senderAddress, params)
204201
}
205202

206203
async function createBork (manager: EntityManager, tx: BorkTxData & { parentTxid?: string }): Promise<void> {
@@ -250,10 +247,11 @@ async function handleCommentReborkLike (manager: EntityManager, tx: BorkTxData):
250247
})
251248
if (!parent) { return }
252249

253-
// create bork if parent exists
250+
// create bork if parent exists, no need to save recipient
254251
await createBork(manager, {
255252
...tx,
256253
parentTxid: parent.txid,
254+
recipientAddress: null,
257255
})
258256
}
259257

@@ -342,46 +340,39 @@ async function handleDelete (manager: EntityManager, tx: BorkTxData): Promise<vo
342340
})
343341
if (!bork) { return }
344342

345-
let conditions: FindConditions<Bork> = {}
346-
let params: Partial<Bork> = { deletedAt: new Date(time) }
347343
switch (bork.type) {
348-
// delete single bork if bork, comment, rebork, extension
344+
// soft delete single bork if bork, comment, rebork, extension
349345
case BorkType.Bork:
350346
case BorkType.Comment:
351347
case BorkType.Rebork:
352348
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+
})
355353
break
356-
// delete all if like, flag, follow, block
354+
// hard delete all if like, flag, follow, block
357355
case BorkType.Like:
358356
case BorkType.Flag:
359357
case BorkType.Follow:
360358
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+
}
364363
// find by parent if like, flag
365364
if ([BorkType.Like, BorkType.Flag].includes(bork.type)) {
366365
conditions.parent = { txid: bork.parentTxid }
367366
// find by recipient if follow, block
368367
} else {
369368
conditions.recipient = { address: bork.recipientAddress }
370369
}
370+
await manager.delete(Bork, conditions)
371371
break
372372
// do nothing if setName, setBio, setAvatar, delete
373373
default:
374374
break
375375
}
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-
])
385376
}
386377

387378
async function cleanupOrphans (): Promise<void> {

0 commit comments

Comments
 (0)