From 4c1410d4c41adc893a8fd21ff7e9626b6e77bc97 Mon Sep 17 00:00:00 2001 From: jszewczulak Date: Mon, 25 Sep 2023 14:32:48 -0400 Subject: [PATCH] feat: DB lookup optimization, code cleanup --- .../workflow/test/test_workflow_batch_update_api.py | 4 ++++ openassessment/workflow/workflow_batch_update_api.py | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/openassessment/workflow/test/test_workflow_batch_update_api.py b/openassessment/workflow/test/test_workflow_batch_update_api.py index 7c96b7a450..a8e261eb24 100644 --- a/openassessment/workflow/test/test_workflow_batch_update_api.py +++ b/openassessment/workflow/test/test_workflow_batch_update_api.py @@ -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 @@ -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() @@ -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() diff --git a/openassessment/workflow/workflow_batch_update_api.py b/openassessment/workflow/workflow_batch_update_api.py index 31e9ebfe33..8be1f12a49 100644 --- a/openassessment/workflow/workflow_batch_update_api.py +++ b/openassessment/workflow/workflow_batch_update_api.py @@ -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 @@ -312,8 +313,7 @@ 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) @@ -321,8 +321,7 @@ def get_workflow_update_data(peer_workflows): 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)