Skip to content

Commit 8a78b61

Browse files
committed
fix: dramatically increase performance for get_my_slots
1 parent d11f7fe commit 8a78b61

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lbplanner/classes/helpers/slot_helper.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ public static function get_all_slots(): array {
107107
return $slotsobj;
108108
}
109109

110+
/**
111+
* Returns a list of all slots relevant for a vintage.
112+
*
113+
* @param string $vintage the vintage to filter for
114+
* @return slot[] An array of the slots.
115+
*/
116+
public static function get_vintage_slots(string $vintage): array {
117+
global $DB;
118+
$slots = $DB->get_records_sql(
119+
'SELECT slot.* FROM {' . self::TABLE_SLOTS . '} as slot ' .
120+
'INNER JOIN {'. self::TABLE_SLOT_FILTERS . '} as filter ON slot.id=filter.slotid ' .
121+
'WHERE filter.vintage=? OR filter.vintage=NULL',
122+
[$vintage]
123+
);
124+
125+
$slotsobj = [];
126+
foreach ($slots as $slot) {
127+
array_push($slotsobj, slot::from_db($slot));
128+
}
129+
130+
return $slotsobj;
131+
}
132+
110133
/**
111134
* Returns a list of all slots belonging to a supervisor.
112135
* @param int $supervisorid userid of the supervisor in question

lbplanner/services/slots/get_my_slots.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function get_my_slots_parameters(): external_function_parameters {
4343
public static function get_my_slots(): array {
4444
global $USER;
4545

46-
$allslots = slot_helper::get_all_slots();
46+
$allslots = slot_helper::get_vintage_slots($USER->address);
4747

4848
$myslots = slot_helper::filter_slots_for_user($allslots, $USER);
4949

0 commit comments

Comments
 (0)