From b037ae5dc1297c9d0ea357c8e813961cba0bcd98 Mon Sep 17 00:00:00 2001 From: Saumya Pandey Date: Wed, 7 Jul 2021 17:23:40 +0530 Subject: [PATCH] fix: Improve isChildDocument performance (#2284) --- server/models/Collection.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/models/Collection.js b/server/models/Collection.js index ea8d4a214..039420c50 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -395,7 +395,11 @@ Collection.prototype.isChildDocument = function ( let result = false; const loopChildren = (documents, input) => { - return documents.map((document) => { + if (result) { + return; + } + + documents.forEach((document) => { let parents = [...input]; if (document.id === documentId) { result = parents.includes(parentDocumentId); @@ -403,7 +407,6 @@ Collection.prototype.isChildDocument = function ( parents.push(document.id); loopChildren(document.children, parents); } - return document; }); };