Просмотр исходного кода

change method name and comment

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

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

@@ -362,14 +362,17 @@ schema.statics.getAggrConditionForPageWithProvidedPathAndDescendants = function(
   ];
 };
 
-// update descendantCount of pages with provided paths by count
-schema.statics.recountDescendantCountOfPathsByCount = async function(paths:string[], count: number):Promise<void> {
+/**
+ * add/subtract descendantCount of pages with provided paths by increment.
+ * increment can be negative number
+ */
+schema.statics.incrementDescendantCountOfPaths = async function(paths:string[], increment: number):Promise<void> {
   const pages = await this.aggregate([{ $match: { path: { $in: paths } } }]);
   const operations = pages.map((page) => {
     return {
       updateOne: {
         filter: { path: page.path },
-        update: { descendantCount: page.descendantCount + count },
+        update: { descendantCount: page.descendantCount + increment },
       },
     };
   });

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

@@ -1296,7 +1296,7 @@ class PageService {
   async updateDescendantCountOfAncestors(path = '/', count = 0) {
     const Page = this.crowi.model('Page');
     const ancestors = collectAncestorPaths(path);
-    await Page.recountDescendantCountOfPathsByCount(ancestors, count);
+    await Page.incrementDescendantCountOfPaths(ancestors, count);
   }
 
 }