From 20ff3920ff775a316b8f64b75c4d5de4b06e9a82 Mon Sep 17 00:00:00 2001 From: Paulo Viadanna Date: Wed, 4 Sep 2024 09:24:34 -0300 Subject: [PATCH] refactor: improve code performance --- openedx/core/djangoapps/discussions/serializers.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/discussions/serializers.py b/openedx/core/djangoapps/discussions/serializers.py index 29403ebde00d..8eeb7e10278a 100644 --- a/openedx/core/djangoapps/discussions/serializers.py +++ b/openedx/core/djangoapps/discussions/serializers.py @@ -265,14 +265,6 @@ def update(self, instance: DiscussionsConfiguration, validated_data: dict) -> Di course_overview_id=instance.context_key, type='discussion' ).update(is_hidden=not instance.enabled) - # do the same for the modulestore representation - store = modulestore() - course = store.get_course(instance.context_key) - for tab in course.tabs: - if tab.tab_id == 'discussion': - tab.is_hidden = not instance.enabled - store.update_item(course, self.context['user_id']) - break update_discussions_settings_from_course_task.delay(str(instance.context_key)) return instance @@ -362,6 +354,12 @@ def _update_course_configuration( key not in LegacySettingsSerializer.Meta.fields_cohorts ) } + # toogle discussion tab is_hidden + for tab in course.tabs: + if tab.tab_id == 'discussion' and tab.is_hidden != instance.enabled: + tab.is_hidden = not instance.enabled + save = True + break if save: modulestore().update_item(course, self.context['user_id']) return instance