yohei0125 3 лет назад
Родитель
Сommit
7841c1cc92
1 измененных файлов с 35 добавлено и 34 удалено
  1. 35 34
      packages/app/src/server/service/page.ts

+ 35 - 34
packages/app/src/server/service/page.ts

@@ -3040,6 +3040,41 @@ class PageService {
     return nMigratablePages;
   }
 
+  /**
+   * 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 updateDescendantCountOfSelfAndDescendants(path: string): Promise<void> {
+    const BATCH_SIZE = 200;
+    const Page = this.crowi.model('Page');
+    const { PageQueryBuilder } = Page;
+
+    const builder = new PageQueryBuilder(Page.find(), true);
+    builder.addConditionAsOnTree();
+    builder.addConditionToListWithDescendants(path);
+    builder.addConditionToSortPagesByDescPath();
+
+    const aggregatedPages = await builder.query.lean().cursor({ batchSize: BATCH_SIZE });
+    await this.recountAndUpdateDescendantCountOfPages(aggregatedPages);
+  }
+
+  /**
+   * update descendantCount of the pages sequentially from path containing more `/` to path containing less
+   */
+  async updateDescendantCountOfPagesWithPaths(paths: string[]): Promise<void> {
+    const BATCH_SIZE = 200;
+    const Page = this.crowi.model('Page');
+    const { PageQueryBuilder } = Page;
+
+    const builder = new PageQueryBuilder(Page.find(), true);
+    builder.addConditionToListByPathsArray(paths); // find by paths
+    builder.addConditionToSortPagesByDescPath(); // sort in DESC
+
+    const aggregatedPages = await builder.query.lean().cursor({ batchSize: BATCH_SIZE });
+    await this.recountAndUpdateDescendantCountOfPages(aggregatedPages);
+  }
+
   /**
    * Recount descendantCount of pages one by one
    */
@@ -3065,25 +3100,6 @@ class PageService {
     await streamToPromise(recountWriteStream);
   }
 
-  /**
-   * 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 updateDescendantCountOfSelfAndDescendants(path: string): Promise<void> {
-    const BATCH_SIZE = 200;
-    const Page = this.crowi.model('Page');
-    const { PageQueryBuilder } = Page;
-
-    const builder = new PageQueryBuilder(Page.find(), true);
-    builder.addConditionAsOnTree();
-    builder.addConditionToListWithDescendants(path);
-    builder.addConditionToSortPagesByDescPath();
-
-    const aggregatedPages = await builder.query.lean().cursor({ batchSize: BATCH_SIZE });
-    await this.recountAndUpdateDescendantCountOfPages(aggregatedPages);
-  }
-
   // update descendantCount of all pages that are ancestors of a provided pageId by count
   async updateDescendantCountOfAncestors(pageId: ObjectIdLike, inc: number, shouldIncludeTarget: boolean): Promise<void> {
     const Page = this.crowi.model('Page');
@@ -3096,21 +3112,6 @@ class PageService {
     this.emitUpdateDescCount(updateDescCountData);
   }
 
-  /**
-   * update descendantCount of the pages sequentially from path containing more `/` to path containing less
-   */
-  async updateDescendantCountOfPagesWithPaths(paths: string[]): Promise<void> {
-    const BATCH_SIZE = 200;
-    const Page = this.crowi.model('Page');
-    const { PageQueryBuilder } = Page;
-
-    const builder = new PageQueryBuilder(Page.find(), true);
-    builder.addConditionToListByPathsArray(paths); // find by paths
-    builder.addConditionToSortPagesByDescPath(); // sort in DESC
-
-    const aggregatedPages = await builder.query.lean().cursor({ batchSize: BATCH_SIZE });
-    await this.recountAndUpdateDescendantCountOfPages(aggregatedPages);
-  }
 
   private emitUpdateDescCount(data: UpdateDescCountRawData): void {
     const socket = this.crowi.socketIoService.getDefaultSocket();