2
0
Эх сурвалжийг харах

Revert "Save descendantCount to update correctly"

This reverts commit 6d4359b6dbfdb220100430c9fd5e3c871a5e6334.
Taichi Masuyama 4 жил өмнө
parent
commit
db76d0513e

+ 1 - 0
packages/app/src/server/interfaces/page-operation.ts

@@ -22,4 +22,5 @@ export type IUserForResuming = {
 export type IOptionsForResuming = {
 export type IOptionsForResuming = {
   updateMetadata?: boolean,
   updateMetadata?: boolean,
   createRedirectPage?: boolean,
   createRedirectPage?: boolean,
+  exDescendantCount?: number,
 };
 };

+ 1 - 0
packages/app/src/server/models/page-operation.ts

@@ -72,6 +72,7 @@ const userSchemaForResuming = new Schema<IUserForResuming>({
 const optionsSchemaForResuming = new Schema<IOptionsForResuming>({
 const optionsSchemaForResuming = new Schema<IOptionsForResuming>({
   createRedirectPage: { type: Boolean },
   createRedirectPage: { type: Boolean },
   updateMetadata: { type: Boolean },
   updateMetadata: { type: Boolean },
+  exDescendantCount: { type: Number },
 }, { _id: false });
 }, { _id: false });
 
 
 const schema = new Schema<PageOperationDocument, PageOperationModel>({
 const schema = new Schema<PageOperationDocument, PageOperationModel>({

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

@@ -2383,6 +2383,13 @@ class PageService {
   }
   }
 
 
   async normalizeParentRecursivelyMainOperation(page, user, pageOpId: ObjectIdLike): Promise<void> {
   async normalizeParentRecursivelyMainOperation(page, user, pageOpId: ObjectIdLike): Promise<void> {
+    // Save exDescendantCount for sub-operation
+    const Page = mongoose.model('Page') as unknown as PageModel;
+    const { PageQueryBuilder } = Page;
+    const builder = new PageQueryBuilder(Page.findOne(), true);
+    builder.addConditionAsMigrated();
+    const exPage = await builder.query.exec();
+    const options = { exDescendantCount: exPage?.descendantCount ?? 0 };
 
 
     try {
     try {
       await this.normalizeParentRecursively([page.path], user);
       await this.normalizeParentRecursively([page.path], user);
@@ -2400,10 +2407,10 @@ class PageService {
       throw Error('PageOperation document not found');
       throw Error('PageOperation document not found');
     }
     }
 
 
-    await this.normalizeParentRecursivelySubOperation(page, user, pageOp._id);
+    await this.normalizeParentRecursivelySubOperation(page, user, pageOp._id, options);
   }
   }
 
 
-  async normalizeParentRecursivelySubOperation(page, user, pageOpId: ObjectIdLike): Promise<void> {
+  async normalizeParentRecursivelySubOperation(page, user, pageOpId: ObjectIdLike, options: {exDescendantCount: number}): Promise<void> {
     const Page = mongoose.model('Page') as unknown as PageModel;
     const Page = mongoose.model('Page') as unknown as PageModel;
 
 
     try {
     try {
@@ -2417,7 +2424,7 @@ class PageService {
         throw Error('Page not found after updating descendantCount');
         throw Error('Page not found after updating descendantCount');
       }
       }
 
 
-      const exDescendantCount = page.descendantCount;
+      const { exDescendantCount } = options;
       const newDescendantCount = pageAfterUpdatingDescendantCount.descendantCount;
       const newDescendantCount = pageAfterUpdatingDescendantCount.descendantCount;
       const inc = (newDescendantCount - exDescendantCount) + 1;
       const inc = (newDescendantCount - exDescendantCount) + 1;
       await this.updateDescendantCountOfAncestors(page._id, inc, false);
       await this.updateDescendantCountOfAncestors(page._id, inc, false);