Skip to content

Commit

Permalink
fix: attempt to optimize get_team_submission_student_ids (#147)
Browse files Browse the repository at this point in the history
* fix: attempt to optimize get_team_submission_student_ids

* fixup! fix: attempt to optimize get_team_submission_student_ids
  • Loading branch information
jansenk authored Dec 3, 2021
1 parent 7b64ffc commit dea46aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion submissions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" API for creating submissions and scores. """
__version__ = '3.4.1'
__version__ = '3.4.2'
11 changes: 5 additions & 6 deletions submissions/team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,12 @@ def get_team_submission_student_ids(team_submission_uuid):
if not team_submission_uuid:
raise TeamSubmissionNotFoundError()
try:
student_ids = StudentItem.objects.filter(
submission__team_submission__uuid=team_submission_uuid
).order_by(
'student_id'
).distinct().values_list(
'student_id', flat=True
student_ids = TeamSubmission.objects.filter(
uuid=team_submission_uuid
).values_list(
'submissions__student_item__student_id', flat=True
)

except DatabaseError as exc:
err_msg = "Attempt to get student ids for team submission {team_submission_uuid} caused error: {exc}".format(
team_submission_uuid=team_submission_uuid,
Expand Down
15 changes: 7 additions & 8 deletions submissions/tests/test_team_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,14 @@ def test_get_team_submission_student_ids(self):
for student_id in submission_2_student_ids:
self._make_individual_submission(student_id, team_submission=team_submission_2)

with self.assertNumQueries(1):
team_1_ids = team_api.get_team_submission_student_ids(str(team_submission.uuid))

team_2_ids = team_api.get_team_submission_student_ids(str(team_submission_2.uuid))

# Assert that each team submission's uuid returns the correct student_ids
self.assertEqual(
team_api.get_team_submission_student_ids(str(team_submission.uuid)),
self.student_ids
)
self.assertEqual(
team_api.get_team_submission_student_ids(str(team_submission_2.uuid)),
submission_2_student_ids
)
self.assertEqual(team_1_ids, self.student_ids)
self.assertEqual(team_2_ids, submission_2_student_ids)

def test_get_team_submission_student_ids__no_team_submission(self):
with self.assertRaises(TeamSubmissionNotFoundError):
Expand Down

0 comments on commit dea46aa

Please sign in to comment.