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

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

@@ -99,7 +99,7 @@ schema.plugin(uniqueValidator);
 /*
 /*
  * Methods
  * Methods
  */
  */
-const collectAncestorPaths = (path: string, ancestorPaths: string[] = []): string[] => {
+export const collectAncestorPaths = (path: string, ancestorPaths: string[] = []): string[] => {
   if (isTopPage(path)) return ancestorPaths;
   if (isTopPage(path)) return ancestorPaths;
 
 
   const parentPath = nodePath.dirname(path);
   const parentPath = nodePath.dirname(path);
@@ -375,9 +375,8 @@ schema.statics.getAggrConditionForPageWithProvidedPathAndDescendants = function(
   ];
   ];
 };
 };
 
 
-// update descendantCount of ancestors of the provided path by count
-schema.statics.recountDescendantCountOfAncestors = async function(path:string, count: number):Promise<void> {
-  const paths = collectAncestorPaths(path);
+// update descendantCount of pages with provided paths by count
+schema.statics.recountDescendantCountOfPathsByCount = async function(paths:string[], count: number):Promise<void> {
   const pages = await this.aggregate([{ $match: { path: { $in: paths } } }]);
   const pages = await this.aggregate([{ $match: { path: { $in: paths } } }]);
   const operations = pages.map((page) => {
   const operations = pages.map((page) => {
     return {
     return {

+ 4 - 3
packages/app/src/server/service/page.js

@@ -1,7 +1,7 @@
 import { pagePathUtils } from '@growi/core';
 import { pagePathUtils } from '@growi/core';
 
 
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
-import { generateGrantCondition } from '~/server/models/page';
+import { generateGrantCondition, collectAncestorPaths } from '~/server/models/page';
 
 
 import { stringifySnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
 import { stringifySnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
 
 
@@ -1290,10 +1290,11 @@ class PageService {
     await streamToPromise(recountWriteStream);
     await streamToPromise(recountWriteStream);
   }
   }
 
 
-  // update descendantCount of all pages that are ancestors of path by passed count
+  // update descendantCount of all pages that are ancestors of a provided path by count
   async updateDescendantCountOfAncestors(path = '/', count = 0) {
   async updateDescendantCountOfAncestors(path = '/', count = 0) {
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
-    await Page.recountDescendantCountOfAncestors(path, count);
+    const ancestors = collectAncestorPaths(path);
+    await Page.recountDescendantCountOfPathsByCount(ancestors, count);
   }
   }
 
 
 }
 }