From 00471d4a789d040957d08ebc9ffdb9c0ff84a733 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Wed, 11 Jan 2017 14:39:10 -0500 Subject: [PATCH] add index for modified to course and subsection grades and first attempted for subsection for TNL-6281 --- .../migrations/0009_auto_20170111_1507.py | 22 +++++++++++++++++++ .../migrations/0010_auto_20170112_1156.py | 18 +++++++++++++++ lms/djangoapps/grades/models.py | 14 ++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lms/djangoapps/grades/migrations/0009_auto_20170111_1507.py create mode 100644 lms/djangoapps/grades/migrations/0010_auto_20170112_1156.py diff --git a/lms/djangoapps/grades/migrations/0009_auto_20170111_1507.py b/lms/djangoapps/grades/migrations/0009_auto_20170111_1507.py new file mode 100644 index 0000000000..d71c45a811 --- /dev/null +++ b/lms/djangoapps/grades/migrations/0009_auto_20170111_1507.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('grades', '0008_persistentsubsectiongrade_first_attempted'), + ] + + operations = [ + migrations.AlterIndexTogether( + name='persistentcoursegrade', + index_together=set([('passed_timestamp', 'course_id'), ('modified', 'course_id')]), + ), + migrations.AlterIndexTogether( + name='persistentsubsectiongrade', + index_together=set([('modified', 'course_id', 'usage_key')]), + ), + ] diff --git a/lms/djangoapps/grades/migrations/0010_auto_20170112_1156.py b/lms/djangoapps/grades/migrations/0010_auto_20170112_1156.py new file mode 100644 index 0000000000..39cf1fdf49 --- /dev/null +++ b/lms/djangoapps/grades/migrations/0010_auto_20170112_1156.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('grades', '0009_auto_20170111_1507'), + ] + + operations = [ + migrations.AlterIndexTogether( + name='persistentsubsectiongrade', + index_together=set([('modified', 'course_id', 'usage_key'), ('first_attempted', 'course_id', 'user_id')]), + ), + ] diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index e95cda16e0..cb21a7539a 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -253,6 +253,17 @@ class PersistentSubsectionGrade(DeleteGradesMixin, TimeStampedModel): # * Course staff can see all grades for a course using (course_id,) ('course_id', 'user_id', 'usage_key'), ] + # Allows querying in the following ways: + # (modified): find all the grades updated within a certain timespan + # (modified, course_id): find all the grades updated within a timespan for a certain course + # (modified, course_id, usage_key): find all the grades updated within a timespan for a subsection + # in a course + # (first_attempted, course_id, user_id): find all attempted subsections in a course for a user + # (first_attempted, course_id): find all attempted subsections in a course for all users + index_together = [ + ('modified', 'course_id', 'usage_key'), + ('first_attempted', 'course_id', 'user_id') + ] # primary key will need to be large for this table id = UnsignedBigIntAutoField(primary_key=True) # pylint: disable=invalid-name @@ -502,11 +513,14 @@ class PersistentCourseGrade(DeleteGradesMixin, TimeStampedModel): # (course_id) for instructors to see all course grades, implicitly created via the unique_together constraint # (user_id) for course dashboard; explicitly declared as an index below # (passed_timestamp, course_id) for tracking when users first earned a passing grade. + # (modified): find all the grades updated within a certain timespan + # (modified, course_id): find all the grades updated within a certain timespan for a course unique_together = [ ('course_id', 'user_id'), ] index_together = [ ('passed_timestamp', 'course_id'), + ('modified', 'course_id') ] # primary key will need to be large for this table