Fix card migration loop (#9176)

Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
Artyom Savchenko 2025-06-05 19:51:01 +07:00 committed by GitHub
parent 852137c213
commit c8604703e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -103,15 +103,21 @@ async function fillParentInfo (client: Client): Promise<void> {
async function getCardParentWithParentInfo (
txOp: TxOperations,
_id: Ref<Card>,
cache: Map<Ref<Card>, Card>
cache: Map<Ref<Card>, Card>,
visited: Set<Ref<Card>> = new Set<Ref<Card>>()
): Promise<Card | undefined> {
if (visited.has(_id)) {
return undefined
}
const doc = cache.get(_id) ?? (await txOp.findOne(card.class.Card, { _id }))
if (doc === undefined) return
if (doc.parentInfo === undefined) {
if (doc.parent == null) {
doc.parentInfo = []
} else {
visited.add(_id) // Add current card to visited set before recursing
const parent = await getCardParentWithParentInfo(txOp, doc.parent, cache)
visited.delete(_id)
if (parent !== undefined) {
doc.parentInfo = [
...(parent.parentInfo ?? []),
@ -122,6 +128,7 @@ async function getCardParentWithParentInfo (
}
]
} else {
doc.parent = null
doc.parentInfo = []
}
}