|
|
@@ -584,6 +584,8 @@ class PageService implements IPageService {
|
|
|
|
|
|
this.activityEvent.emit('updated', activity, page, preNotify);
|
|
|
}
|
|
|
+
|
|
|
+ this.disableAncestorPagesTtl(newPagePath);
|
|
|
return renamedPage;
|
|
|
}
|
|
|
|
|
|
@@ -3812,9 +3814,10 @@ class PageService implements IPageService {
|
|
|
page.parent = parent._id;
|
|
|
}
|
|
|
|
|
|
- // Set wip
|
|
|
+ // Make WIP
|
|
|
if (options.wip) {
|
|
|
- page.makeWip();
|
|
|
+ const hasChildren = await Page.exists({ parent: page._id });
|
|
|
+ page.makeWip(hasChildren != null); // disableTtl = hasChildren != null
|
|
|
}
|
|
|
|
|
|
// Save
|
|
|
@@ -3855,6 +3858,8 @@ class PageService implements IPageService {
|
|
|
* Used to run sub operation in create method
|
|
|
*/
|
|
|
async createSubOperation(page, user, options: IOptionsForCreate, pageOpId: ObjectIdLike): Promise<void> {
|
|
|
+ await this.disableAncestorPagesTtl(page.path);
|
|
|
+
|
|
|
// Update descendantCount
|
|
|
await this.updateDescendantCountOfAncestors(page._id, 1, false);
|
|
|
|
|
|
@@ -3939,6 +3944,18 @@ class PageService implements IPageService {
|
|
|
return this.canProcessCreate(path, grantData, false);
|
|
|
}
|
|
|
|
|
|
+ private async disableAncestorPagesTtl(path: string): Promise<void> {
|
|
|
+ const Page = mongoose.model<PageDocument, PageModel>('Page');
|
|
|
+
|
|
|
+ const ancestorPaths = collectAncestorPaths(path);
|
|
|
+ const ancestorPageIds = await Page.aggregate([
|
|
|
+ { $match: { path: { $in: ancestorPaths, $nin: ['/'] }, isEmpty: false } },
|
|
|
+ { $project: { _id: 1 } },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ await Page.updateMany({ _id: { $in: ancestorPageIds } }, { $unset: { ttlTimestamp: true } });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @private
|
|
|
* This method receives the same arguments as the PageService.create method does except for the added type '{ grantUserIds?: ObjectIdLike[] }'.
|
|
|
@@ -4413,6 +4430,34 @@ class PageService implements IPageService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async createTtlIndex(): Promise<void> {
|
|
|
+ const wipPageExpirationSeconds = configManager.getConfig('crowi', 'app:wipPageExpirationSeconds') ?? 172800;
|
|
|
+ const collection = mongoose.connection.collection('pages');
|
|
|
+
|
|
|
+ try {
|
|
|
+ const targetField = 'ttlTimestamp_1';
|
|
|
+
|
|
|
+ const indexes = await collection.indexes();
|
|
|
+ const foundTargetField = indexes.find(i => i.name === targetField);
|
|
|
+
|
|
|
+ const isNotSpec = foundTargetField?.expireAfterSeconds == null || foundTargetField?.expireAfterSeconds !== wipPageExpirationSeconds;
|
|
|
+ const shoudDropIndex = foundTargetField != null && isNotSpec;
|
|
|
+ const shoudCreateIndex = foundTargetField == null || shoudDropIndex;
|
|
|
+
|
|
|
+ if (shoudDropIndex) {
|
|
|
+ await collection.dropIndex(targetField);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shoudCreateIndex) {
|
|
|
+ await collection.createIndex({ ttlTimestamp: 1 }, { expireAfterSeconds: wipPageExpirationSeconds });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Failed to create TTL Index', err);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default PageService;
|