From 2235501de8132af0f5e8a082320de3993c02c17a Mon Sep 17 00:00:00 2001 From: Stoorx Date: Tue, 17 Sep 2024 18:43:20 +0300 Subject: [PATCH] Optimize _build_feedback_options_cells The function have been rewrited to perform exactly one query. Also, the join function was used to avoid string copying. --- openassessment/data.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/openassessment/data.py b/openassessment/data.py index 2f116f5467..5ce2cfb611 100644 --- a/openassessment/data.py +++ b/openassessment/data.py @@ -597,14 +597,9 @@ def _build_feedback_options_cell(cls, assessments): Returns: string that should be included in the relevant 'feedback_options' column for this set of assessments' row """ - - returned_string = "" - for assessment in assessments: - for feedback in assessment.assessment_feedback.all(): - for option in feedback.options.all(): - returned_string += option.text + "\n" - - return returned_string + return '\n'.join(Assessment.objects + .filter(id__in=(a.id for a in assessments), assessment_feedback__options__text__isnull=False) + .values_list('assessment_feedback__options__text', flat=True)) @classmethod def _build_feedback_cell(cls, submission_uuid):