Skip to content

Commit 73b9cd6

Browse files
committed
fix: add index for course id in user stats
The query to look up users by which ones have a course stat for a particular course is very slow when there are a large number of courses and users. This change adds an index for that field so that looking up users based on their course stats should be much faster.
1 parent c7cb15b commit 73b9cd6

3 files changed

+3
-0
lines changed

models/user.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class User
2727
validates_uniqueness_of :username
2828

2929
index( {external_id: 1}, {unique: true, background: true} )
30+
index( {'course_stats.course_id': 1}, {background: true} )
3031

3132
logger = Logger.new(STDOUT)
3233
logger.level = Logger::WARN
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.users.ensureIndex({'course_stats.course_id': 1}, { background: true })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.users.dropIndex({'course_stats.course_id': 1})

0 commit comments

Comments
 (0)