Skip to content

Commit

Permalink
perf: optimizations for SortedModelSelect2Multiple.optgroups (#4538)
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila authored Jan 9, 2025
1 parent f238b3e commit c76a7af
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions course_discovery/apps/course_metadata/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ def optgroups(self, name, value, attrs=None):
only support one main group (because that's all we need right now).
"""
selected = []
unselected = []
for index, (option_value, option_label) in enumerate(chain(self.choices)):
is_selected = str(option_value) in value
subgroup = [self.create_option(name, option_value, option_label, is_selected, index, attrs=attrs)]
item = (None, subgroup, index)
if is_selected:
subgroup = [self.create_option(name, option_value, option_label, is_selected, index, attrs=attrs)]
item = (None, subgroup, index)
selected.append(item)
else:
unselected.append(item)

ordered = []
for value_id in value:
for item in selected:
if value_id == str(item[1][0]['value']):
ordered.append(item)
break

return ordered

0 comments on commit c76a7af

Please sign in to comment.