Fix not checking null on dbtangle call

This commit is contained in:
Jacob Karlsson 2024-06-05 17:29:54 +02:00
parent b851d3eaf1
commit 2b74aa6b1a
2 changed files with 6 additions and 2 deletions

View File

@ -10,6 +10,7 @@ const { EMPTY_RANGE, isEmptyRange, estimateMsgCount } = require('./range')
* @typedef {ReturnType<import('pzp-dict').init>} PZPDict
* @typedef {ReturnType<import('pzp-set').init>} PZPSet
* @typedef {import('pzp-db/msg-v4').Msg} Msg
* @typedef {import('pzp-db/db-tangle')} DBTangle
* @typedef {import('pzp-goals').Goal} Goal
* @typedef {import('./range').Range} Range
* @typedef {string} MsgID
@ -314,12 +315,15 @@ class Algorithm {
* @param {number} count
*/
async pruneNewest(rootID, count) {
/** @type {DBTangle | null} */
const tangle = await p(this.#peer.db.getTangle)(rootID)
if (!tangle) return
const sorted = tangle.topoSort()
if (sorted.length <= count) return
const msgID = sorted[sorted.length - count] // New "oldest dataful msg"
const { deletables, erasables } = tangle.getDeletablesAndErasables(msgID)
const deletablesErasables = tangle.getDeletablesAndErasables(msgID)
if (!deletablesErasables) return
const { deletables, erasables } = deletablesErasables
const del = p(this.#peer.db.del)
const erase = p(this.#peer.db.erase)
for (const msgID of deletables) {

View File

@ -38,7 +38,7 @@
"@types/node": "16.x",
"c8": "7",
"pzp-caps": "^1.0.0",
"pzp-db": "^1.0.1",
"pzp-db": "^1.0.4",
"pzp-dict": "^1.0.0",
"pzp-goals": "^1.0.0",
"pzp-keypair": "^1.0.0",