diff --git a/models/action.js b/models/action.js index 8aa7322e3..e378eec18 100644 --- a/models/action.js +++ b/models/action.js @@ -21,8 +21,8 @@ const ActionSchema = new Schema({ item_id: String, user_id: String, - // The element that summaries will additionally group on in addtion to their action_type, item_type, and - // item_id. + // The element that summaries will additionally group on in addition to their + // action_type, item_type, and item_id. group_id: String, // Additional metadata stored on the field. @@ -34,6 +34,14 @@ const ActionSchema = new Schema({ } }); +// Create an index on the `item_id` field so that queries looking for +// actions based on the item id can resolve faster. +ActionSchema.index({ + 'item_id': 1 +}, { + background: true +}); + const Action = mongoose.model('Action', ActionSchema); module.exports = Action;