|
@ -26,7 +26,8 @@ const CommentSchema = new Schema({ |
|
|
created: { type: Date, default: Date.now, required: true, index: 1 }, |
|
|
created: { type: Date, default: Date.now, required: true, index: 1 }, |
|
|
resourceType: { type: String, enum: RESOURCE_TYPE_LIST, required: true }, |
|
|
resourceType: { type: String, enum: RESOURCE_TYPE_LIST, required: true }, |
|
|
resource: { type: Schema.ObjectId, required: true, index: 1, refPath: 'resourceType' }, |
|
|
resource: { type: Schema.ObjectId, required: true, index: 1, refPath: 'resourceType' }, |
|
|
author: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' }, |
|
|
authorType: { type: String, enum: ['User', 'CoreUser'], required: true}, |
|
|
|
|
|
author: { type: Schema.ObjectId, required: true, index: 1, refPath: 'authorType' }, |
|
|
replyTo: { type: Schema.ObjectId, index: 1, ref: 'Comment' }, |
|
|
replyTo: { type: Schema.ObjectId, index: 1, ref: 'Comment' }, |
|
|
status: { type: String, enum: COMMENT_STATUS_LIST, default: 'published', required: true }, |
|
|
status: { type: String, enum: COMMENT_STATUS_LIST, default: 'published', required: true }, |
|
|
content: { type: String, required: true, maxlength: 3000 }, |
|
|
content: { type: String, required: true, maxlength: 3000 }, |
|
@ -37,12 +38,27 @@ const CommentSchema = new Schema({ |
|
|
stats: { type: CommentStats, default: CommentStatsDefaults, required: true }, |
|
|
stats: { type: CommentStats, default: CommentStatsDefaults, required: true }, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* An index to optimize finding comments authored by a specific author. It helps |
|
|
|
|
|
* to use authorType as a pre-filter, then find the author by ID. This compound |
|
|
|
|
|
* index accomplishes that. The author's comments are then indexed by status for |
|
|
|
|
|
* additional filtering and speed. |
|
|
|
|
|
*/ |
|
|
|
|
|
CommentSchema.index({ |
|
|
|
|
|
authorType: 1, |
|
|
|
|
|
author: 1, |
|
|
|
|
|
status: 1, |
|
|
|
|
|
}, { |
|
|
|
|
|
name: 'comment_author_by_type', |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* An index to optimize finding replies to a specific comment |
|
|
* An index to optimize finding replies to a specific comment |
|
|
*/ |
|
|
*/ |
|
|
CommentSchema.index({ |
|
|
CommentSchema.index({ |
|
|
resource: 1, |
|
|
resource: 1, |
|
|
replyTo: 1, |
|
|
replyTo: 1, |
|
|
|
|
|
status: 1, |
|
|
}, { |
|
|
}, { |
|
|
partialFilterExpression: { replyTo: { $exists: true } }, |
|
|
partialFilterExpression: { replyTo: { $exists: true } }, |
|
|
name: 'comment_replies', |
|
|
name: 'comment_replies', |
|
|