| 2049 | // compression: after resolving, seed the map with the resolved link so |
| 2050 | // subsequent survivors sharing the same chain segment don't re-walk. |
| 2051 | const resolve = (start: UUID): UUID | null => { |
| 2052 | const path: UUID[] = [] |
| 2053 | let cur: UUID | null | undefined = start |
| 2054 | while (cur && toDelete.has(cur)) { |
| 2055 | path.push(cur) |
| 2056 | cur = deletedParent.get(cur) |
| 2057 | if (cur === undefined) { |
| 2058 | cur = null |
| 2059 | break |
| 2060 | } |
| 2061 | } |
| 2062 | for (const p of path) deletedParent.set(p, cur) |
| 2063 | return cur |
| 2064 | } |
| 2065 | let relinkedCount = 0 |
| 2066 | for (const [uuid, msg] of messages) { |
| 2067 | if (!msg.parentUuid || !toDelete.has(msg.parentUuid)) continue |