| 2170 | // compression: after resolving, seed the map with the resolved link so |
| 2171 | // subsequent survivors sharing the same chain segment don't re-walk. |
| 2172 | const resolve = (start: UUID): UUID | null => { |
| 2173 | const path: UUID[] = [] |
| 2174 | let cur: UUID | null | undefined = start |
| 2175 | while (cur && toDelete.has(cur)) { |
| 2176 | path.push(cur) |
| 2177 | cur = deletedParent.get(cur) |
| 2178 | if (cur === undefined) { |
| 2179 | cur = null |
| 2180 | break |
| 2181 | } |
| 2182 | } |
| 2183 | for (const p of path) deletedParent.set(p, cur) |
| 2184 | return cur |
| 2185 | } |
| 2186 | let relinkedCount = 0 |
| 2187 | for (const [uuid, msg] of messages) { |
| 2188 | if (!msg.parentUuid || !toDelete.has(msg.parentUuid)) continue |