From 66f068359fa774ba630d821998539b9158c5c256 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 4 Jan 2018 14:14:27 -0700 Subject: [PATCH] Added index for `item_id` on Actions. --- models/action.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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;