yohei0125 4 лет назад
Родитель
Сommit
33538e9aea
2 измененных файлов с 7 добавлено и 5 удалено
  1. 6 4
      packages/app/src/server/models/page.ts
  2. 1 1
      packages/app/src/server/service/page.js

+ 6 - 4
packages/app/src/server/models/page.ts

@@ -342,14 +342,17 @@ schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: strin
 };
 
 /**
- * return aggregation to get pages with paths starting with the provided path
+ * 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
  */
-schema.statics.getAggrConditionForPagesStartingWithProvidedPath = function(path:string) {
+schema.statics.getAggrConditionForPageWithProvidedPathAndDescendants = function(path:string) {
   const match = {
     $match: {
       $or: [
         {
-          path: { $regex: `^${path}.*` },
+          // https://regex101.com/r/ncnxaR/1
+          path: { $regex: `^${path}(/.*|$)` },
           parent: { $ne: null },
         },
         { path: '/' },
@@ -358,7 +361,6 @@ schema.statics.getAggrConditionForPagesStartingWithProvidedPath = function(path:
   };
   return [
     match,
-    // https://regex101.com/r/Nax9Ms/1
     {
       $project: {
         path: 1,

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

@@ -1253,7 +1253,7 @@ class PageService {
     const BATCH_SIZE = 200;
     const Page = this.crowi.model('Page');
 
-    const aggregateCondition = Page.getAggrConditionForPagesStartingWithProvidedPath(path);
+    const aggregateCondition = Page.getAggrConditionForPageWithProvidedPathAndDescendants(path);
     const aggregatedPages = await Page.aggregate(aggregateCondition).cursor({ batchSize: BATCH_SIZE });
 
     const recountWriteStream = new Writable({