mirror of https://codeberg.org/pzp/pzp-gc.git
cleanup can erase or del based on record purpose
This commit is contained in:
parent
c7d743f589
commit
889d003be4
18
lib/index.js
18
lib/index.js
|
@ -26,17 +26,23 @@ module.exports = {
|
|||
// State
|
||||
const debug = makeDebug('ppppp:gc')
|
||||
|
||||
/**
|
||||
* Deletes messages that don't correspond to any goal.
|
||||
* @private
|
||||
*/
|
||||
function cleanup(cb) {
|
||||
debug('cleanup goalless started')
|
||||
const done = multicb({ pluck: 1 })
|
||||
let waitingForDels = false
|
||||
let waiting = false
|
||||
for (const rec of peer.db.records()) {
|
||||
if (!rec.msg) continue
|
||||
const goals = peer.goals.getByRec(rec)
|
||||
if (goals.length === 0) {
|
||||
const purpose = peer.goals.getRecordPurpose(rec)
|
||||
if (purpose === 'none') {
|
||||
peer.db.del(rec.id, done())
|
||||
waitingForDels = true
|
||||
} else {
|
||||
waiting = true
|
||||
} else if (purpose === 'trail') {
|
||||
peer.db.erase(rec.id, done())
|
||||
waiting = true
|
||||
}
|
||||
}
|
||||
function whenEnded(err) {
|
||||
|
@ -45,7 +51,7 @@ module.exports = {
|
|||
else debug('cleanup goalless ended')
|
||||
cb()
|
||||
}
|
||||
if (waitingForDels) done(whenEnded)
|
||||
if (waiting) done(whenEnded)
|
||||
else whenEnded()
|
||||
}
|
||||
|
||||
|
|
|
@ -40,25 +40,26 @@ test('feed holes', async (t) => {
|
|||
await p(alice.db.del)(posts[3])
|
||||
await p(alice.db.del)(posts[4])
|
||||
await p(alice.db.del)(posts[5])
|
||||
await p(alice.db.del)(posts[6])
|
||||
await p(alice.db.erase)(posts[6]) // vital as trail from A7
|
||||
assert('alice deleted the middle part of the feed')
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
['A0', 'A1', 'A2', 'A7', 'A8', 'A9'],
|
||||
['A0', 'A1', 'A2', /* */ 'A7', 'A8', 'A9'],
|
||||
'alice has the beginning and the end of the feed'
|
||||
)
|
||||
|
||||
alice.goals.set(aliceID, 'all') // alice wants her account tangle
|
||||
const postFeedID = alice.db.feed.getID(aliceID, 'post')
|
||||
alice.goals.set(postFeedID, 'newest-3')
|
||||
assert('alice set a goal for newest-3 of post feed')
|
||||
// notice 4 on purpose, because we want to make sure A2 is deleted
|
||||
alice.goals.set(postFeedID, 'newest-4')
|
||||
assert('alice set a goal for newest-4 of post feed')
|
||||
|
||||
await p(alice.gc.forceImmediately)()
|
||||
|
||||
assert.deepEqual(
|
||||
getTexts([...alice.db.msgs()]),
|
||||
['A7', 'A8', 'A9'],
|
||||
[/* */ 'A7', 'A8', 'A9'],
|
||||
'alice has only the end of the feed'
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue