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
|
// State
|
||||||
const debug = makeDebug('ppppp:gc')
|
const debug = makeDebug('ppppp:gc')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes messages that don't correspond to any goal.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
function cleanup(cb) {
|
function cleanup(cb) {
|
||||||
debug('cleanup goalless started')
|
debug('cleanup goalless started')
|
||||||
const done = multicb({ pluck: 1 })
|
const done = multicb({ pluck: 1 })
|
||||||
let waitingForDels = false
|
let waiting = false
|
||||||
for (const rec of peer.db.records()) {
|
for (const rec of peer.db.records()) {
|
||||||
if (!rec.msg) continue
|
if (!rec.msg) continue
|
||||||
const goals = peer.goals.getByRec(rec)
|
const purpose = peer.goals.getRecordPurpose(rec)
|
||||||
if (goals.length === 0) {
|
if (purpose === 'none') {
|
||||||
peer.db.del(rec.id, done())
|
peer.db.del(rec.id, done())
|
||||||
waitingForDels = true
|
waiting = true
|
||||||
} else {
|
} else if (purpose === 'trail') {
|
||||||
|
peer.db.erase(rec.id, done())
|
||||||
|
waiting = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function whenEnded(err) {
|
function whenEnded(err) {
|
||||||
|
@ -45,7 +51,7 @@ module.exports = {
|
||||||
else debug('cleanup goalless ended')
|
else debug('cleanup goalless ended')
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
if (waitingForDels) done(whenEnded)
|
if (waiting) done(whenEnded)
|
||||||
else 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[3])
|
||||||
await p(alice.db.del)(posts[4])
|
await p(alice.db.del)(posts[4])
|
||||||
await p(alice.db.del)(posts[5])
|
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('alice deleted the middle part of the feed')
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
getTexts([...alice.db.msgs()]),
|
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 has the beginning and the end of the feed'
|
||||||
)
|
)
|
||||||
|
|
||||||
alice.goals.set(aliceID, 'all') // alice wants her account tangle
|
alice.goals.set(aliceID, 'all') // alice wants her account tangle
|
||||||
const postFeedID = alice.db.feed.getID(aliceID, 'post')
|
const postFeedID = alice.db.feed.getID(aliceID, 'post')
|
||||||
alice.goals.set(postFeedID, 'newest-3')
|
// notice 4 on purpose, because we want to make sure A2 is deleted
|
||||||
assert('alice set a goal for newest-3 of post feed')
|
alice.goals.set(postFeedID, 'newest-4')
|
||||||
|
assert('alice set a goal for newest-4 of post feed')
|
||||||
|
|
||||||
await p(alice.gc.forceImmediately)()
|
await p(alice.gc.forceImmediately)()
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
getTexts([...alice.db.msgs()]),
|
getTexts([...alice.db.msgs()]),
|
||||||
['A7', 'A8', 'A9'],
|
[/* */ 'A7', 'A8', 'A9'],
|
||||||
'alice has only the end of the feed'
|
'alice has only the end of the feed'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue