fix: Double recursive loops can cause server lockup on deeply nested docs (#5222)
This commit is contained in:
@@ -10,10 +10,10 @@ import { parser } from "@server/editor";
|
||||
* @returns An array of document identifiers
|
||||
*/
|
||||
export default function parseDocumentIds(text: string): string[] {
|
||||
const value = parser.parse(text);
|
||||
const doc = parser.parse(text);
|
||||
const identifiers: string[] = [];
|
||||
|
||||
function findLinks(node: Node) {
|
||||
doc.descendants((node: Node) => {
|
||||
// get text nodes
|
||||
if (node.type.name === "text") {
|
||||
// get marks for text nodes
|
||||
@@ -28,15 +28,12 @@ export default function parseDocumentIds(text: string): string[] {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!node.content.size) {
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
node.content.descendants(findLinks);
|
||||
}
|
||||
|
||||
findLinks(value);
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user