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

Merge pull request #6018 from weseek/feat/increase-in-Main-and-decrease-in-Sub-of-descendant-count

feat: Increase and decrease the number of parent's descendantCount in rename(Main/Sub)Operation
Yohei Shiina 3 лет назад
Родитель
Сommit
ea66021a4d
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      packages/app/src/server/service/page.ts

+ 10 - 1
packages/app/src/server/service/page.ts

@@ -539,6 +539,11 @@ class PageService {
     }
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
 
+    // 5.increase parent's descendantCount.
+    // see: https://dev.growi.org/62149d019311629d4ecd91cf#Handling%20of%20descendantCount%20in%20case%20of%20unexpected%20process%20interruption
+    const nToIncreaseForOperationInterruption = 1;
+    await Page.incrementDescendantCountOfPageIds([newParent._id], nToIncreaseForOperationInterruption);
+
     // create page redirect
     if (options.createRedirectPage) {
       const PageRedirect = mongoose.model('PageRedirect') as unknown as PageRedirectModel;
@@ -578,7 +583,11 @@ class PageService {
       this.crowi.pageOperationService.clearAutoUpdateInterval(timerObj);
     }
 
-    // reduce ancestore's descendantCount
+    // reduce parent's descendantCount
+    // see: https://dev.growi.org/62149d019311629d4ecd91cf#Handling%20of%20descendantCount%20in%20case%20of%20unexpected%20process%20interruption
+    const nToReduceForOperationInterruption = -1;
+    await Page.incrementDescendantCountOfPageIds([renamedPage.parent], nToReduceForOperationInterruption);
+
     const nToReduce = -1 * ((page.isEmpty ? 0 : 1) + page.descendantCount);
     await this.updateDescendantCountOfAncestors(exParentId, nToReduce, true);