|
@@ -310,7 +310,7 @@ schema.statics.findChildrenByParentPathOrIdAndViewer = async function(parentPath
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: string, user, userGroups = null): Promise<Record<string, PageDocument[]>> {
|
|
schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: string, user, userGroups = null): Promise<Record<string, PageDocument[]>> {
|
|
|
- const ancestorPaths = isTopPage(path) ? ['/'] : collectAncestorPaths(path);
|
|
|
|
|
|
|
+ const ancestorPaths = isTopPage(path) ? ['/'] : collectAncestorPaths(path); // root path is necessary for rendering
|
|
|
const regexps = ancestorPaths.map(path => new RegExp(generateChildrenRegExp(path))); // cannot use re2
|
|
const regexps = ancestorPaths.map(path => new RegExp(generateChildrenRegExp(path))); // cannot use re2
|
|
|
|
|
|
|
|
// get pages at once
|
|
// get pages at once
|
|
@@ -330,10 +330,18 @@ schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: strin
|
|
|
return page;
|
|
return page;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // make map
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * If any non-migrated page is found during creating the pathToChildren map, it will stop incrementing at that moment
|
|
|
|
|
+ */
|
|
|
const pathToChildren: Record<string, PageDocument[]> = {};
|
|
const pathToChildren: Record<string, PageDocument[]> = {};
|
|
|
- ancestorPaths.forEach((path) => {
|
|
|
|
|
- pathToChildren[path] = pages.filter(page => nodePath.dirname(page.path) === path);
|
|
|
|
|
|
|
+ const sortedPaths = ancestorPaths.sort((a, b) => a.length - b.length); // sort paths by path.length
|
|
|
|
|
+ sortedPaths.every((path) => {
|
|
|
|
|
+ const children = pages.filter(page => nodePath.dirname(page.path) === path);
|
|
|
|
|
+ if (children.length === 0) {
|
|
|
|
|
+ return false; // break when children do not exist
|
|
|
|
|
+ }
|
|
|
|
|
+ pathToChildren[path] = children;
|
|
|
|
|
+ return true;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return pathToChildren;
|
|
return pathToChildren;
|