mirror of https://codeberg.org/pzp/pzp-gc.git
dont erase a trail msg redundantly
This commit is contained in:
parent
94f5160f07
commit
9075f983d8
28
lib/index.js
28
lib/index.js
|
@ -55,12 +55,12 @@ function initGC(peer, config) {
|
|||
const done = multicb({ pluck: 1 })
|
||||
|
||||
/**
|
||||
* @param {string} explanation
|
||||
* @param {string} errExplanation
|
||||
*/
|
||||
function makeRecCB(explanation) {
|
||||
function makeRecCB(errExplanation) {
|
||||
const cb = done()
|
||||
return (/**@type {Error=}*/ err) => {
|
||||
if (err) debug('%s: %s', explanation, flattenCauseChain(err))
|
||||
if (err) debug('%s: %s', errExplanation, flattenCauseChain(err))
|
||||
cb()
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,18 @@ function initGC(peer, config) {
|
|||
if (!rec.msg) continue
|
||||
const { id: msgID, msg } = rec
|
||||
const [purpose, details] = peer.goals.getMsgPurpose(msgID, msg)
|
||||
if (purpose === 'goal') continue // don't cleanup
|
||||
if (purpose === 'none') {
|
||||
switch (purpose) {
|
||||
case 'goal': {
|
||||
continue // don't cleanup
|
||||
}
|
||||
case 'none': {
|
||||
const recCB = makeRecCB('Failed to delete msg when cleaning up')
|
||||
debug('Deleting msg %s with purpose=none', msgID)
|
||||
peer.db.del(msgID, recCB)
|
||||
waiting = true
|
||||
} else if (purpose === 'ghost') {
|
||||
continue
|
||||
}
|
||||
case 'ghost': {
|
||||
const { tangleID, span } = details
|
||||
const recCB = makeRecCB('Failed to delete ghost msg when cleaning up')
|
||||
// TODO: Could one msg be a ghostable in MANY tangles? Or just one?
|
||||
|
@ -86,13 +91,20 @@ function initGC(peer, config) {
|
|||
peer.db.del(msgID, recCB)
|
||||
})
|
||||
waiting = true
|
||||
} else if (purpose === 'trail') {
|
||||
continue
|
||||
}
|
||||
case 'trail': {
|
||||
if (!msg.data) continue // it's already erased
|
||||
const recCB = makeRecCB('Failed to erase trail msg when cleaning up')
|
||||
debug('Erasing msg %s with purpose=trail', msgID)
|
||||
peer.db.erase(msgID, recCB)
|
||||
waiting = true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
default: {
|
||||
cb(new Error('Unreachable'))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,16 @@ test('Feed holes', async (t) => {
|
|||
alice.goals.set(postFeedID, 'newest-4')
|
||||
assert('alice set a goal for newest-4 of post feed')
|
||||
|
||||
// Mock db.erase so we can inspect how many times it was called
|
||||
const prevErase = alice.db.erase
|
||||
const calledErase = []
|
||||
alice.db.erase = (msgID, cb) => {
|
||||
calledErase.push(msgID)
|
||||
prevErase(msgID, cb)
|
||||
}
|
||||
|
||||
await p(alice.gc.forceImmediately)()
|
||||
assert.deepEqual(calledErase, [posts[2]], 'erased A2')
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
|
@ -60,5 +69,8 @@ test('Feed holes', async (t) => {
|
|||
'alice has only the end of the feed'
|
||||
)
|
||||
|
||||
await p(alice.gc.forceImmediately)()
|
||||
assert.deepEqual(calledErase, [posts[2]], 'no double erasing')
|
||||
|
||||
await p(alice.close)(true)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue