yohei0125 4 лет назад
Родитель
Сommit
9da7cab116
2 измененных файлов с 19 добавлено и 13 удалено
  1. 14 12
      packages/app/src/server/models/page.ts
  2. 5 1
      packages/app/src/server/service/page.js

+ 14 - 12
packages/app/src/server/models/page.ts

@@ -345,20 +345,22 @@ schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: strin
  * return aggregate condition to get following pages
  * - page that has the same path as the provided path
  * - pages that are descendants of the above page
+ * pages without parent will be ignored
  */
 schema.statics.getAggrConditionForPageWithProvidedPathAndDescendants = function(path:string) {
-  const match = {
-    $match: {
-      $or: [
-        {
-          // https://regex101.com/r/ncnxaR/1
-          path: { $regex: `^${path}(/.*|$)` },
-          parent: { $ne: null },
-        },
-        { path: '/' },
-      ],
-    },
-  };
+  let match;
+  if (isTopPage(path)) {
+    match = {
+      // https://regex101.com/r/Kip2rV/1
+      $match: { $or: [{ path: { $regex: '^/.*' }, parent: { $ne: null } }, { path: '/' }] },
+    };
+  }
+  else {
+    match = {
+      // https://regex101.com/r/mJvGrG/1
+      $match: { path: { $regex: `^${path}(/.*|$)` }, parent: { $ne: null } },
+    };
+  }
   return [
     match,
     {

+ 5 - 1
packages/app/src/server/service/page.js

@@ -1248,7 +1248,11 @@ class PageService {
     return Page.count({ parent: null, creator: user, grant: { $ne: Page.GRANT_PUBLIC } });
   }
 
-  // update descendantCount of all pages with path starting with provided string
+  /**
+   * update descendantCount of the following pages
+   * - page that has the same path as the provided path
+   * - pages that are descendants of the above page
+   */
   async updateSelfAndDescendantCount(path = '/') {
     const BATCH_SIZE = 200;
     const Page = this.crowi.model('Page');