Преглед изворни кода

Revert "Fix create pages recusrively"

This reverts commit 7789a63856961298b6291919e041ab87fef5fe4f.
Mudana-Grune пре 3 година
родитељ
комит
c5a7d539a8
2 измењених фајлова са 17 додато и 46 уклоњено
  1. 15 39
      packages/app/src/server/models/page.ts
  2. 2 7
      packages/app/src/server/service/page.ts

+ 15 - 39
packages/app/src/server/models/page.ts

@@ -671,55 +671,18 @@ schema.statics.findTargetAndAncestorsByPathOrId = async function(pathOrId: strin
   return { targetAndAncestors, rootPage };
   return { targetAndAncestors, rootPage };
 };
 };
 
 
-/*
- * Utils from obsolete-page.js
- */
-export async function pushRevision(pageData, newRevision, user) {
-  await newRevision.save();
-
-  pageData.revision = newRevision;
-  pageData.lastUpdateUser = user?._id ?? user;
-  pageData.updatedAt = Date.now();
-
-  return pageData.save();
-}
-
 /**
 /**
  * Create empty pages at paths at which no pages exist
  * Create empty pages at paths at which no pages exist
  * @param paths Page paths
  * @param paths Page paths
  * @param aggrPipelineForExistingPages AggregationPipeline object to find existing pages at paths
  * @param aggrPipelineForExistingPages AggregationPipeline object to find existing pages at paths
  */
  */
-schema.statics.createEmptyPagesByPaths = async function(paths: string[], aggrPipelineForExistingPages: any[], user?: IUserHasId): Promise<void> {
+schema.statics.createEmptyPagesByPaths = async function(paths: string[], aggrPipelineForExistingPages: any[]): Promise<void> {
   const existingPages = await this.aggregate(aggrPipelineForExistingPages);
   const existingPages = await this.aggregate(aggrPipelineForExistingPages);
 
 
   const existingPagePaths = existingPages.map(page => page.path);
   const existingPagePaths = existingPages.map(page => page.path);
   const notExistingPagePaths = paths.filter(path => !existingPagePaths.includes(path));
   const notExistingPagePaths = paths.filter(path => !existingPagePaths.includes(path));
-  if (user != null) {
-    const Revision = mongoose.model('Revision') as any;
-    // Create and save pages
-    const createPagesAndRevisions = notExistingPagePaths.map(async(path) => {
-      const page = await this.create({ path, isEmpty: false, descendantCount: 0 });
-
-      // Get number of descendants
-      const descendantCount = await this.countDocuments({ path: { $regex: `^${path}/` } });
-
-      // Update descendantCount
-      page.descendantCount = descendantCount;
-      await page.save();
-
-      // Create revision and push it to the page
-      const newRevision = Revision.prepareRevision(page, '', null, user, { format: 'markdown' });
-      await pushRevision(page, newRevision, user);
-      await page.populateDataToShowRevision();
-
-      return page;
-    });
 
 
-    await Promise.all(createPagesAndRevisions);
-  }
-  else {
-    await this.insertMany(notExistingPagePaths.map(path => ({ path, isEmpty: true })));
-  }
+  await this.insertMany(notExistingPagePaths.map(path => ({ path, isEmpty: true })));
 };
 };
 
 
 /**
 /**
@@ -743,6 +706,19 @@ schema.statics.findParentByPath = async function(path: string): Promise<PageDocu
   return null;
   return null;
 };
 };
 
 
+/*
+ * Utils from obsolete-page.js
+ */
+export async function pushRevision(pageData, newRevision, user) {
+  await newRevision.save();
+
+  pageData.revision = newRevision;
+  pageData.lastUpdateUser = user?._id ?? user;
+  pageData.updatedAt = Date.now();
+
+  return pageData.save();
+}
+
 /**
 /**
  * add/subtract descendantCount of pages with provided paths by increment.
  * add/subtract descendantCount of pages with provided paths by increment.
  * increment can be negative number
  * increment can be negative number

+ 2 - 7
packages/app/src/server/service/page.ts

@@ -561,12 +561,6 @@ class PageService {
     const nToIncrease = (renamedPage.isEmpty ? 0 : 1) + page.descendantCount;
     const nToIncrease = (renamedPage.isEmpty ? 0 : 1) + page.descendantCount;
     await this.updateDescendantCountOfAncestors(renamedPage._id, nToIncrease, false);
     await this.updateDescendantCountOfAncestors(renamedPage._id, nToIncrease, false);
 
 
-    // Remove leaf empty pages if not moving to under the ex-target position
-    if (!this.isRenamingToUnderTarget(page.path, newPagePath)) {
-      // remove empty pages at leaf position
-      await Page.removeLeafEmptyPagesRecursively(page.parent);
-    }
-
     await PageOperation.findByIdAndDelete(pageOpId);
     await PageOperation.findByIdAndDelete(pageOpId);
   }
   }
 
 
@@ -3347,7 +3341,8 @@ class PageService {
 
 
     // Fill ancestors
     // Fill ancestors
     const aggregationPipeline: any[] = await this.buildPipelineToCreateEmptyPagesByUser(user, ancestorPaths);
     const aggregationPipeline: any[] = await this.buildPipelineToCreateEmptyPagesByUser(user, ancestorPaths);
-    await Page.createEmptyPagesByPaths(ancestorPaths, aggregationPipeline, user);
+
+    await Page.createEmptyPagesByPaths(ancestorPaths, aggregationPipeline);
 
 
     // Connect ancestors
     // Connect ancestors
     await this.connectPageTree(path);
     await this.connectPageTree(path);