mirror of https://codeberg.org/pzp/pzp-db.git
avoid infinite loop in Tangle.precedes()
This commit is contained in:
parent
001fcaa1ab
commit
17742f9ed2
|
@ -296,13 +296,19 @@ class Tangle {
|
||||||
if (msgAID === msgBID) return false
|
if (msgAID === msgBID) return false
|
||||||
if (msgBID === this.#rootID) return false
|
if (msgBID === this.#rootID) return false
|
||||||
let toCheck = [msgBID]
|
let toCheck = [msgBID]
|
||||||
|
const checked = new Set()
|
||||||
while (toCheck.length > 0) {
|
while (toCheck.length > 0) {
|
||||||
const checking = /** @type {string} */ (toCheck.shift())
|
const checking = /** @type {string} */ (toCheck.shift())
|
||||||
|
checked.add(checking)
|
||||||
const prev = this.#prev.get(checking)
|
const prev = this.#prev.get(checking)
|
||||||
if (!prev) continue
|
if (!prev) continue
|
||||||
if (prev.includes(msgAID)) return true
|
if (prev.includes(msgAID)) {
|
||||||
toCheck.push(...prev)
|
checked.clear()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
toCheck.push(...prev.filter((p) => !checked.has(p)))
|
||||||
|
}
|
||||||
|
checked.clear()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue