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 (msgBID === this.#rootID) return false
|
||||
let toCheck = [msgBID]
|
||||
const checked = new Set()
|
||||
while (toCheck.length > 0) {
|
||||
const checking = /** @type {string} */ (toCheck.shift())
|
||||
checked.add(checking)
|
||||
const prev = this.#prev.get(checking)
|
||||
if (!prev) continue
|
||||
if (prev.includes(msgAID)) return true
|
||||
toCheck.push(...prev)
|
||||
if (prev.includes(msgAID)) {
|
||||
checked.clear()
|
||||
return true
|
||||
}
|
||||
toCheck.push(...prev.filter((p) => !checked.has(p)))
|
||||
}
|
||||
checked.clear()
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue