mirror of https://codeberg.org/pzp/pzp-db.git
getTangleDeletablesAndErasables()
This commit is contained in:
parent
fd7b76808b
commit
01cb78c65a
|
@ -273,6 +273,8 @@ exports.init = function initDB(peer, config) {
|
|||
|
||||
function del(msgId, cb) {
|
||||
const rec = getRecord(msgId)
|
||||
if (!rec) return cb()
|
||||
if (!rec.msg) return cb()
|
||||
const { offset, size, seq } = rec.misc
|
||||
recs[rec.misc.seq] = { misc: { offset, size, seq } }
|
||||
log.onDrain(() => {
|
||||
|
@ -282,11 +284,19 @@ exports.init = function initDB(peer, config) {
|
|||
|
||||
function erase(msgId, cb) {
|
||||
const rec = getRecord(msgId)
|
||||
if (!rec) return cb()
|
||||
if (!rec.msg) return cb()
|
||||
if (!rec.msg.content) return cb()
|
||||
recs[rec.misc.seq].msg = FeedV1.erase(rec.msg)
|
||||
// FIXME: persist this change to disk!! Not supported by AAOL yet
|
||||
cb()
|
||||
}
|
||||
|
||||
function getTangleDeletablesAndErasables(tangleId, msgHash) {
|
||||
const tangle = new Tangle(tangleId, records())
|
||||
return tangle.getDeletablesAndErasables(msgHash)
|
||||
}
|
||||
|
||||
function* msgs() {
|
||||
for (let i = 0; i < recs.length; i++) {
|
||||
const rec = recs[i]
|
||||
|
@ -313,6 +323,7 @@ exports.init = function initDB(peer, config) {
|
|||
del,
|
||||
erase,
|
||||
onRecordAdded,
|
||||
getTangleDeletablesAndErasables,
|
||||
msgs,
|
||||
records,
|
||||
|
||||
|
|
|
@ -186,13 +186,13 @@ class Tangle {
|
|||
}
|
||||
|
||||
getDeletablesAndErasables(msgHash) {
|
||||
const emptyables = this.#shortestPathToRoot(msgHash)
|
||||
const erasables = this.#shortestPathToRoot(msgHash)
|
||||
const sorted = this.topoSort()
|
||||
const index = sorted.indexOf(msgHash)
|
||||
const deletables = sorted.filter(
|
||||
(msgHash, i) => i < index && !emptyables.includes(msgHash)
|
||||
(msgHash, i) => i < index && !erasables.includes(msgHash)
|
||||
)
|
||||
return { deletables, emptyables }
|
||||
return { deletables, erasables }
|
||||
}
|
||||
|
||||
getMaxDepth() {
|
||||
|
|
|
@ -163,19 +163,19 @@ test('Tangle.getLipmaaSet', (t) => {
|
|||
|
||||
test('Tangle.getDeletablesAndErasables basic', (t) => {
|
||||
const tangle = new Tangle(rootPost, peer.db.records())
|
||||
const { deletables, emptyables } = tangle.getDeletablesAndErasables(reply2A)
|
||||
const { deletables, erasables } = tangle.getDeletablesAndErasables(reply2A)
|
||||
|
||||
t.deepEquals(deletables, [reply1Hi], 'deletables')
|
||||
t.deepEquals(emptyables, [reply1Lo, rootPost], 'emptyables')
|
||||
t.deepEquals(erasables, [reply1Lo, rootPost], 'erasables')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Tangle.getDeletablesAndErasables with lipmaa', (t) => {
|
||||
const tangle = new Tangle(rootPost, peer.db.records())
|
||||
const { deletables, emptyables } = tangle.getDeletablesAndErasables(reply3Lo)
|
||||
const { deletables, erasables } = tangle.getDeletablesAndErasables(reply3Lo)
|
||||
|
||||
t.deepEquals(deletables, [reply1Lo, reply1Hi, reply2A], 'deletables')
|
||||
t.deepEquals(emptyables, [rootPost], 'emptyables')
|
||||
t.deepEquals(erasables, [rootPost], 'erasables')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue