|
|
@@ -2555,15 +2555,13 @@ class PageService {
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
- // limit pages to get
|
|
|
+ // Limit pages to get
|
|
|
const total = await Page.countDocuments(filter);
|
|
|
if (total > PAGES_LIMIT) {
|
|
|
baseAggregation = baseAggregation.limit(Math.floor(total * 0.3));
|
|
|
}
|
|
|
|
|
|
const pagesStream = await baseAggregation.cursor({ batchSize: BATCH_SIZE });
|
|
|
-
|
|
|
- // use batch stream
|
|
|
const batchStream = createBatchStream(BATCH_SIZE);
|
|
|
|
|
|
let countPages = 0;
|
|
|
@@ -2574,10 +2572,15 @@ class PageService {
|
|
|
async write(pages, encoding, callback) {
|
|
|
const parentPaths = Array.from(new Set<string>(pages.map(p => pathlib.dirname(p.path))));
|
|
|
|
|
|
- // Fill parents with empty pages
|
|
|
+ // 1. Remove unnecessary empty pages
|
|
|
+ const pageIdsToNotDelete = pages.map(p => p._id);
|
|
|
+ const emptyPagePathsToDelete = pages.map(p => p.path);
|
|
|
+ await Page.removeEmptyPages(pageIdsToNotDelete, emptyPagePathsToDelete);
|
|
|
+
|
|
|
+ // 2. Create lacking parents as empty pages
|
|
|
await Page.createEmptyPagesByPaths(parentPaths, user, false);
|
|
|
|
|
|
- // Find parents
|
|
|
+ // 3. Find parents
|
|
|
const builder = new PageQueryBuilder(Page.find({}, { _id: 1, path: 1 }), true);
|
|
|
const parents = await builder
|
|
|
.addConditionToListByPathsArray(parentPaths)
|
|
|
@@ -2632,9 +2635,6 @@ class PageService {
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
- // Remove unnecessary empty pages
|
|
|
- await Page.removeEmptyPages(pages.map(p => p._id), pages.map(p => p.path));
|
|
|
-
|
|
|
callback();
|
|
|
},
|
|
|
final(callback) {
|