Commit ec90200b by Victor Shnayder

fix migration to remove out of date index

* reorder index fields
parent d9c753e7
...@@ -76,7 +76,7 @@ def grade(student, request, course, student_module_cache=None): ...@@ -76,7 +76,7 @@ def grade(student, request, course, student_module_cache=None):
# TODO: We may be able to speed this up by only getting a list of children IDs from section_module # TODO: We may be able to speed this up by only getting a list of children IDs from section_module
# Then, we may not need to instatiate any problems if they are already in the database # Then, we may not need to instatiate any problems if they are already in the database
for module in yield_module_descendents(section_module): for module in yield_module_descendents(section_module):
(correct, total) = get_score(student, module, student_module_cache) (correct, total) = get_score(course.id, student, module, student_module_cache)
if correct is None and total is None: if correct is None and total is None:
continue continue
...@@ -171,7 +171,9 @@ def progress_summary(student, course, grader, student_module_cache): ...@@ -171,7 +171,9 @@ def progress_summary(student, course, grader, student_module_cache):
graded = s.metadata.get('graded', False) graded = s.metadata.get('graded', False)
scores = [] scores = []
for module in yield_module_descendents(s): for module in yield_module_descendents(s):
(correct, total) = get_score(student, module, student_module_cache) # course is a module, not a descriptor...
course_id = course.descriptor.id
(correct, total) = get_score(course_id, student, module, student_module_cache)
if correct is None and total is None: if correct is None and total is None:
continue continue
...@@ -200,7 +202,7 @@ def progress_summary(student, course, grader, student_module_cache): ...@@ -200,7 +202,7 @@ def progress_summary(student, course, grader, student_module_cache):
return chapters return chapters
def get_score(user, problem, student_module_cache): def get_score(course_id, user, problem, student_module_cache):
""" """
Return the score for a user on a problem, as a tuple (correct, total). Return the score for a user on a problem, as a tuple (correct, total).
...@@ -215,7 +217,7 @@ def get_score(user, problem, student_module_cache): ...@@ -215,7 +217,7 @@ def get_score(user, problem, student_module_cache):
correct = 0.0 correct = 0.0
# If the ID is not in the cache, add the item # If the ID is not in the cache, add the item
instance_module = get_instance_module(user, problem, student_module_cache) instance_module = get_instance_module(course_id, user, problem, student_module_cache)
# instance_module = student_module_cache.lookup(problem.category, problem.id) # instance_module = student_module_cache.lookup(problem.category, problem.id)
# if instance_module is None: # if instance_module is None:
# instance_module = StudentModule(module_type=problem.category, # instance_module = StudentModule(module_type=problem.category,
......
...@@ -9,6 +9,8 @@ class Migration(SchemaMigration): ...@@ -9,6 +9,8 @@ class Migration(SchemaMigration):
def forwards(self, orm): def forwards(self, orm):
# NOTE (vshnayder): This constraint has the wrong field order, so it doesn't actually
# do anything. Migration 0004 actually removes this index.
# Removing unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student'] # Removing unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student']
db.delete_unique('courseware_studentmodule', ['module_id', 'module_type', 'student_id']) db.delete_unique('courseware_studentmodule', ['module_id', 'module_type', 'student_id'])
......
...@@ -16,13 +16,17 @@ class Migration(SchemaMigration): ...@@ -16,13 +16,17 @@ class Migration(SchemaMigration):
# Removing unique constraint on 'StudentModule', fields ['module_id', 'student'] # Removing unique constraint on 'StudentModule', fields ['module_id', 'student']
db.delete_unique('courseware_studentmodule', ['module_id', 'student_id']) db.delete_unique('courseware_studentmodule', ['module_id', 'student_id'])
# NOTE: manually remove this constaint (from 0001)--0003 tries, but fails.
# Removing unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student']
db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type'])
# Adding unique constraint on 'StudentModule', fields ['course_id', 'module_state_key', 'student'] # Adding unique constraint on 'StudentModule', fields ['course_id', 'module_state_key', 'student']
db.create_unique('courseware_studentmodule', ['course_id', 'module_id', 'student_id']) db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'course_id'])
def backwards(self, orm): def backwards(self, orm):
# Removing unique constraint on 'StudentModule', fields ['course_id', 'module_state_key', 'student'] # Removing unique constraint on 'StudentModule', fields ['studnet_id', 'module_state_key', 'course_id']
db.delete_unique('courseware_studentmodule', ['course_id', 'module_id', 'student_id']) db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'course_id'])
# Deleting field 'StudentModule.course_id' # Deleting field 'StudentModule.course_id'
db.delete_column('courseware_studentmodule', 'course_id') db.delete_column('courseware_studentmodule', 'course_id')
...@@ -30,6 +34,9 @@ class Migration(SchemaMigration): ...@@ -30,6 +34,9 @@ class Migration(SchemaMigration):
# Adding unique constraint on 'StudentModule', fields ['module_id', 'student'] # Adding unique constraint on 'StudentModule', fields ['module_id', 'student']
db.create_unique('courseware_studentmodule', ['module_id', 'student_id']) db.create_unique('courseware_studentmodule', ['module_id', 'student_id'])
# Adding unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student']
db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type'])
models = { models = {
'auth.group': { 'auth.group': {
......
...@@ -43,7 +43,7 @@ class StudentModule(models.Model): ...@@ -43,7 +43,7 @@ class StudentModule(models.Model):
course_id = models.CharField(max_length=255, db_index=True) course_id = models.CharField(max_length=255, db_index=True)
class Meta: class Meta:
unique_together = (('course_id', 'student', 'module_state_key'),) unique_together = (('student', 'module_state_key', 'course_id'),)
## Internal state of the object ## Internal state of the object
state = models.TextField(null=True, blank=True) state = models.TextField(null=True, blank=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment