|
@@ -117,10 +117,19 @@ class PageService {
|
|
|
return PageTagRelation.insertMany(newPageTagRelation, { ordered: false });
|
|
return PageTagRelation.insertMany(newPageTagRelation, { ordered: false });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async duplicateDescendants(pages, user, oldPagePathPrefix, newPagePathPrefix, pathRevisionMapping) {
|
|
|
|
|
|
|
+ async duplicateDescendants(pages, user, oldPagePathPrefix, newPagePathPrefix) {
|
|
|
const Page = this.crowi.model('Page');
|
|
const Page = this.crowi.model('Page');
|
|
|
const Revision = this.crowi.model('Revision');
|
|
const Revision = this.crowi.model('Revision');
|
|
|
|
|
|
|
|
|
|
+ const paths = pages.map(page => (page.path));
|
|
|
|
|
+ const revisions = await Revision.find({ path: { $in: paths } });
|
|
|
|
|
+
|
|
|
|
|
+ // Mapping to set to the body of the new revision
|
|
|
|
|
+ const pathRevisionMapping = {};
|
|
|
|
|
+ revisions.forEach((revision) => {
|
|
|
|
|
+ pathRevisionMapping[revision.path] = revision;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// key: oldPageId, value: newPageId
|
|
// key: oldPageId, value: newPageId
|
|
|
const pageIdMapping = {};
|
|
const pageIdMapping = {};
|
|
|
const newPages = [];
|
|
const newPages = [];
|
|
@@ -157,10 +166,8 @@ class PageService {
|
|
|
|
|
|
|
|
async duplicateDescendantsWithStream(page, newPagePath, user) {
|
|
async duplicateDescendantsWithStream(page, newPagePath, user) {
|
|
|
const Page = this.crowi.model('Page');
|
|
const Page = this.crowi.model('Page');
|
|
|
- const Revision = this.crowi.model('Revision');
|
|
|
|
|
const newPagePathPrefix = newPagePath;
|
|
const newPagePathPrefix = newPagePath;
|
|
|
const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
|
|
const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
|
|
|
- const revisions = await Revision.find({ path: pathRegExp });
|
|
|
|
|
|
|
|
|
|
const { PageQueryBuilder } = Page;
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
|
@@ -172,12 +179,6 @@ class PageService {
|
|
|
.lean()
|
|
.lean()
|
|
|
.cursor();
|
|
.cursor();
|
|
|
|
|
|
|
|
- // Mapping to set to the body of the new revision
|
|
|
|
|
- const pathRevisionMapping = {};
|
|
|
|
|
- revisions.forEach((revision) => {
|
|
|
|
|
- pathRevisionMapping[revision.path] = revision;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
const duplicateDescendants = this.duplicateDescendants.bind(this);
|
|
const duplicateDescendants = this.duplicateDescendants.bind(this);
|
|
|
let count = 0;
|
|
let count = 0;
|
|
|
const writeStream = new Writable({
|
|
const writeStream = new Writable({
|
|
@@ -185,7 +186,7 @@ class PageService {
|
|
|
async write(batch, encoding, callback) {
|
|
async write(batch, encoding, callback) {
|
|
|
try {
|
|
try {
|
|
|
count += batch.length;
|
|
count += batch.length;
|
|
|
- await duplicateDescendants(batch, user, pathRegExp, newPagePathPrefix, pathRevisionMapping);
|
|
|
|
|
|
|
+ await duplicateDescendants(batch, user, pathRegExp, newPagePathPrefix);
|
|
|
logger.debug(`Adding pages progressing: (count=${count})`);
|
|
logger.debug(`Adding pages progressing: (count=${count})`);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|