Skip to content

Commit 24ca210

Browse files
author
Noemie Ariste
committed
Improve performance of get_all_groups_of_choices
1 parent de61f8d commit 24ca210

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

locallib.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,17 @@ private function process_action_manual_allocation() {
765765
* @return array of group ids used in rateable choices
766766
*/
767767
public function get_all_groups_of_choices(): array {
768-
$rateablechoiceswithgrouprestrictions = array_filter($this->get_rateable_choices(),
769-
fn($choice) => !empty($choice->usegroups) && !empty($this->get_choice_groups($choice->id)));
770-
$rateablechoiceids = array_map(fn($choice) => $choice->id, $rateablechoiceswithgrouprestrictions);
771-
$groupids = [];
772-
foreach ($rateablechoiceids as $choiceid) {
773-
$groupids = array_merge($groupids, array_map(fn($group) => $group->id, $this->get_choice_groups($choiceid)));
774-
}
775-
return array_unique($groupids);
768+
global $DB;
769+
770+
$sql = 'SELECT DISTINCT g.id
771+
FROM {ratingallocate_group_choices} gc
772+
JOIN {ratingallocate_choices} rc on rc.id = gc.choiceid
773+
JOIN {groups} g ON gc.groupid=g.id
774+
WHERE rc.ratingallocateid=:id';
775+
776+
$groupids = $DB->get_fieldset_sql($sql, ['id' => $this->ratingallocateid]);
777+
778+
return $groupids;
776779
}
777780

778781
/**

0 commit comments

Comments
 (0)