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

Remove leaf pages in sub operation

Taichi Masuyama 4 лет назад
Родитель
Сommit
4e7ae2d44e
1 измененных файлов с 9 добавлено и 12 удалено
  1. 9 12
      packages/app/src/server/service/page.ts

+ 9 - 12
packages/app/src/server/service/page.ts

@@ -434,19 +434,13 @@ class PageService {
       }
     }
 
-    const pathToTest = escapeStringRegexp(addTrailingSlash(page.path));
-    const pathToBeTested = newPagePath;
-    const isRenamingToUnderExTarget = (new RegExp(`^${pathToTest}`)).test(pathToBeTested);
-
     // 1. Take target off from tree
     await Page.takeOffFromTree(page._id);
-    console.log('00000', newPagePath, await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
 
     // 2. Find new parent
     const update: Partial<IPage> = {};
     // find or create parent
     const newParent = await Page.getParentAndFillAncestors(newPagePath);
-    console.log('11111', newPagePath, await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
 
     // 3. Put back target page to tree (also update the other attrs)
     update.path = newPagePath;
@@ -456,12 +450,6 @@ class PageService {
       update.updatedAt = new Date();
     }
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
-    console.log('2w222', await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
-    // Remove leaf empty pages if not moving to under the ex-target position
-    if (!isRenamingToUnderExTarget) {
-      // remove empty pages at leaf position
-      await Page.removeLeafEmptyPagesRecursively(page.parent);
-    }
 
     // create page redirect
     if (options.createRedirectPage) {
@@ -498,6 +486,15 @@ class PageService {
     const nToIncrease = (renamedPage.isEmpty ? 0 : 1) + page.descendantCount;
     await this.updateDescendantCountOfAncestors(renamedPage._id, nToIncrease, false);
 
+    // Remove leaf empty pages if not moving to under the ex-target position
+    const pathToTest = escapeStringRegexp(addTrailingSlash(page.path));
+    const pathToBeTested = newPagePath;
+    const isRenamingToUnderExTarget = (new RegExp(`^${pathToTest}`)).test(pathToBeTested);
+    if (!isRenamingToUnderExTarget) {
+      // remove empty pages at leaf position
+      await Page.removeLeafEmptyPagesRecursively(page.parent);
+    }
+
     await PageOperation.findByIdAndDelete(pageOpId);
   }