Skip to content

Commit

Permalink
refactor: improve code performance
Browse files Browse the repository at this point in the history
  • Loading branch information
viadanna committed Sep 4, 2024
1 parent d7357b9 commit 20ff392
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions openedx/core/djangoapps/discussions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20ff392

Please sign in to comment.