Skip to content

Commit

Permalink
feat: DB lookup optimization, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jszewczulak committed Sep 25, 2023
1 parent 48c8ab3 commit 4c1410d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def test_get_blocked_peer_workflows(self):
self.assertEqual(len(blocked), 0)

# set Tim's submission create_at date to >7 days ago
# set Tim's peer workflow completion at 3 days ago
pw_tim = PeerWorkflow.objects.get(student_id=_tim["student_id"])
pw_tim.created_at = timezone.now() - datetime.timedelta(days=8)
pw_tim.completed_at = timezone.now() - datetime.timedelta(days=3)
pw_tim.save()
blocked = update_api.get_blocked_peer_workflows()
# we expect 1 blocked submission
Expand Down Expand Up @@ -69,6 +71,7 @@ def test_get_blocked_peer_workflows_for_course(self):

pw_pat = PeerWorkflow.objects.get(student_id=_pat["student_id"])
pw_pat.created_at = timezone.now() - datetime.timedelta(days=8)
pw_pat.completed_at = timezone.now() - datetime.timedelta(days=3)
pw_pat.course_id = "course_1"
pw_pat.save()

Expand Down Expand Up @@ -99,6 +102,7 @@ def test_get_blocked_peer_workflows_for_ora_block(self):

pw_pat = PeerWorkflow.objects.get(student_id=_pat["student_id"])
pw_pat.created_at = timezone.now() - datetime.timedelta(days=8)
pw_pat.completed_at = timezone.now() - datetime.timedelta(days=3)
pw_pat.item_id = "item_1"
pw_pat.save()

Expand Down
7 changes: 3 additions & 4 deletions openassessment/workflow/workflow_batch_update_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def get_blocked_peer_workflows(course_id=None, item_id=None, submission_uuid=Non
filters = {
'created_at__lte': timezone.now() - datetime.timedelta(days=7),
'grading_completed_at__isnull': True,
'completed_at__isnull': False
}
if course_id is not None:
filters['course_id'] = course_id
Expand Down Expand Up @@ -312,17 +313,15 @@ def get_workflow_update_data(peer_workflows):
for peer_workflow in peer_workflows:

try:
# pylint: disable=consider-iterating-dictionary
if peer_workflow.course_id not in course_settings_cache.keys():
if peer_workflow.course_id not in course_settings_cache:
# retrieve course block from DB
course_block_key = UsageKey.from_string(peer_workflow.course_id)
course_block = store.get_item(course_block_key)
# add course settings to temp cache
course_settings_cache[peer_workflow.course_id] = {
'force_on_flexible_peer_openassessments': course_block.force_on_flexible_peer_openassessments}

# pylint: disable=consider-iterating-dictionary
if peer_workflow.item_id not in assessment_requirements_cache.keys():
if peer_workflow.item_id not in assessment_requirements_cache:
# retrieve openassessment block from DB
ora_block_key = UsageKey.from_string(peer_workflow.item_id)
ora_block = store.get_item(ora_block_key)
Expand Down

0 comments on commit 4c1410d

Please sign in to comment.