Skip to content

Commit b92010a

Browse files
committed
improve performance of get_count_of_courses_to_trigger_for_workflow
1 parent d12b303 commit b92010a

File tree

3 files changed

+11
-32
lines changed

3 files changed

+11
-32
lines changed

classes/local/manager/delayed_courses_manager.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,8 @@ public static function set_course_delayed($courseid, $duration, $delaytype = 0)
131131
*/
132132
public static function get_course_delayed($courseid) {
133133
global $DB;
134-
$record = $DB->get_record('tool_lifecycle_delayed', ['courseid' => $courseid]);
135-
if ($record) {
136-
return $record->delayeduntil;
137-
} else {
138-
return null;
139-
}
134+
$delayeduntil = $DB->get_field('tool_lifecycle_delayed', 'delayeduntil', ['courseid' => $courseid]);
135+
return $delayeduntil ?? 0;
140136
}
141137

142138
/**
@@ -148,12 +144,9 @@ public static function get_course_delayed($courseid) {
148144
*/
149145
public static function get_course_delayed_workflow($courseid, $workflowid) {
150146
global $DB;
151-
$record = $DB->get_record('tool_lifecycle_delayed_workf', ['courseid' => $courseid, 'workflowid' => $workflowid]);
152-
if ($record) {
153-
return $record->delayeduntil;
154-
} else {
155-
return null;
156-
}
147+
$delayeduntil = $DB->get_field('tool_lifecycle_delayed_workf', 'delayeduntil',
148+
['courseid' => $courseid, 'workflowid' => $workflowid]);
149+
return $delayeduntil ?? 0;
157150
}
158151

159152
/**

classes/local/manager/process_manager.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,10 @@ public static function get_process_by_course_id($courseid) {
236236
public static function has_other_process($courseid, $workflowid) {
237237
global $DB;
238238

239-
$ret = 0;
240-
$records = $DB->get_records('tool_lifecycle_process', ['courseid' => $courseid], '', 'id, workflowid');
241-
foreach ($records as $record) {
242-
if ($record->workflowid != $workflowid) {
243-
$ret = 2;
244-
break;
245-
}
246-
$ret = 1;
247-
}
248-
if ($ret != 2) {
249-
$records = $DB->get_records('tool_lifecycle_proc_error', ['courseid' => $courseid], '', 'id, workflowid');
250-
foreach ($records as $record) {
251-
if ($record->workflowid != $workflowid) {
252-
$ret = 2;
253-
break;
254-
}
255-
$ret = 1;
256-
}
239+
if (!$ret = $DB->record_exists_select('tool_lifecycle_process',
240+
"courseid = $courseid and workflowid <> $workflowid")) {
241+
$ret = $DB->record_exists_select('tool_lifecycle_proc_error',
242+
"courseid = $courseid and workflowid <> $workflowid");
257243
}
258244
return $ret;
259245
}

classes/processor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ public function get_count_of_courses_to_trigger_for_workflow($workflow) {
312312

313313
while ($recordset->valid()) {
314314
$course = $recordset->current();
315-
$delaytime = max(delayed_courses_manager::get_course_delayed($course->id) ?? 0,
316-
delayed_courses_manager::get_course_delayed_workflow($course->id, $workflow->id) ?? 0);
315+
$delaytime = max(delayed_courses_manager::get_course_delayed($course->id),
316+
delayed_courses_manager::get_course_delayed_workflow($course->id, $workflow->id));
317317
$coursedelayed = $delaytime > time();
318318
if ($hasother = process_manager::has_other_process($course->id, $workflow->id)) {
319319
if ($hasother == OTHERWORKFLOW) {

0 commit comments

Comments
 (0)