Commit c724f314 by Andrew Dekker

Single query fix

parent 100c1961
......@@ -381,7 +381,7 @@ def get_top_submissions(course_id, item_id, item_type, number_of_top_scores):
student_item__course_id=course_id,
student_item__item_id=item_id,
student_item__item_type=item_type,
).order_by("-points_earned")[:number_of_top_scores]
).select_related("submission").order_by("-points_earned")[:number_of_top_scores]
except DatabaseError:
msg = u"Could not fetch top scores for course {}, item {} of type {}".format(
course_id, item_id, item_type
......
......@@ -298,9 +298,8 @@ class TestSubmissionsApi(TestCase):
api.set_score(student_3['uuid'], 2, 10)
#Get top scores works correctly
with self.assertNumQueries(4):
with self.assertNumQueries(1):
top_scores = api.get_top_submissions(student_item["course_id"], student_item["item_id"], "Peer_Submission", 3)
print top_scores
self.assertEqual(
top_scores,
[
......@@ -321,7 +320,6 @@ class TestSubmissionsApi(TestCase):
#Fewer top scores available than the number requested.
top_scores = api.get_top_submissions(student_item["course_id"], student_item["item_id"], "Peer_Submission", 10)
print top_scores
self.assertEqual(
top_scores,
[
......@@ -342,7 +340,6 @@ class TestSubmissionsApi(TestCase):
#More top scores available than the number requested.
top_scores = api.get_top_submissions(student_item["course_id"], student_item["item_id"], "Peer_Submission", 2)
print top_scores
self.assertEqual(
top_scores,
[
......
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