Skip to content

Commit

Permalink
MBS-7377: Fix workflowoverview for big instances
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed May 19, 2023
1 parent 0318800 commit 053d163
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
4 changes: 4 additions & 0 deletions lang/de/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
$string['config_delay_duration_desc'] = 'Diese Einstellung definiert den Standardlänge einer Kursausschlusses in einem Workflow
falls ein Prozess des Workflows zurückgesetzt oder beendigt wird. Die Länge des Kursausschlusses besagt, wie lange es dauert, bis
der Kurs wieder vom Workflow bearbeitet wird.';
$string['config_showcoursecounts'] = 'Zeige Anzahl der Kurse, die getriggert werden';
$string['config_showcoursecounts_desc'] = 'Die Workflow-Konfigurationsseite zeigt normalerweise die Anzahl an Kursen, die durch
die konfigurierten Trigger getriggert werden, was Performance-Probleme verursachen kann. Bei Performance-Problemen kann dies hiermit
deaktiviert werden';
$string['find_course_list_header'] = 'Kurse finden';
$string['adminsettings_heading'] = 'Workflow-Einstellungen';
$string['active_manual_workflows_heading'] = 'Aktive manuelle Workflows';
Expand Down
4 changes: 4 additions & 0 deletions lang/en/tool_lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
$string['config_backup_path'] = 'Path of the lifecycle backup folder';
$string['config_backup_path_desc'] = 'This settings defines the storage location of the backups created by the backup step.
The path has to be specified as an absolute path on your server.';
$string['config_showcoursecounts'] = 'Show amount of courses which will be triggered';
$string['config_showcoursecounts_desc'] = 'The workflow overview page by default shows the amount of courses which will be
triggered by the configured triggers which can be load heavy. Disable this option if you experience issues loading the workflow
overview.';
$string['find_course_list_header'] = 'Find courses';
$string['adminsettings_heading'] = 'Workflow settings';
$string['active_manual_workflows_heading'] = 'Active manual workflows';
Expand Down
5 changes: 5 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
get_string('config_backup_path_desc', 'tool_lifecycle'),
$CFG->dataroot . DIRECTORY_SEPARATOR . 'lifecycle_backups'));

$settings->add(new admin_setting_configcheckbox('tool_lifecycle/showcoursecounts',
get_string('config_showcoursecounts', 'tool_lifecycle'),
get_string('config_showcoursecounts_desc', 'tool_lifecycle'),
1));

$ADMIN->add('lifecycle_category', new admin_externalpage('tool_lifecycle_workflow_drafts',
get_string('workflow_drafts_header', 'tool_lifecycle'),
new moodle_url(\tool_lifecycle\urls::WORKFLOW_DRAFTS)));
Expand Down
14 changes: 9 additions & 5 deletions templates/workflowoverview.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@
<div class="mt-5 mb-3">{{{addinstance}}}</div>
<div class="wf-trigger-block workflow-item">
<h5 class="my-2">{{#str}} trigger, tool_lifecycle{{/str}} {{{triggerhelp}}}</h5>
{{#automatic}}
{{#showcoursecounts}}
{{#automatic}}
<div class="mb-2 mx-2">
{{#str}} courses_will_be_triggered_total, tool_lifecycle, {{coursestriggered}} {{/str}}<br>
{{#str}} courses_will_be_excluded_total, tool_lifecycle, {{coursesexcluded}} {{/str}}<br>
</div>
{{/automatic}}
{{/automatic}}
{{/showcoursecounts}}
<div class="workflow wf-trigger-wrapper">
{{#trigger}}
<div class="workflow-trigger">
Expand All @@ -103,10 +105,12 @@
</div>
</div>
<div class="wf-content">
{{#showcoursecounts}}
{{#automatic}}
<span>{{#str}} courses_will_be_triggered, tool_lifecycle, {{triggeredcourses}} {{/str}}</span><br>
<span>{{#str}} courses_will_be_excluded, tool_lifecycle, {{excludedcourses}} {{/str}}</span>
<span>{{#str}} courses_will_be_triggered, tool_lifecycle, {{triggeredcourses}} {{/str}}</span><br>
<span>{{#str}} courses_will_be_excluded, tool_lifecycle, {{excludedcourses}} {{/str}}</span>
{{/automatic}}
{{/showcoursecounts}}
</div>
</div>
{{/trigger}}
Expand Down Expand Up @@ -140,4 +144,4 @@
{{{ table }}}
</div>
{{/table}}
</div>
</div>
32 changes: 21 additions & 11 deletions workflowoverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@
'move_down' => get_string('move_down', 'tool_lifecycle')
];

$amounts = (new \tool_lifecycle\processor())->get_count_of_courses_to_trigger_for_workflow($workflow->id);
$displaytotaltriggered = !empty($triggers);
$showcoursecounts = get_config('tool_lifecycle', 'showcoursecounts');
if ($showcoursecounts) {
// On moodle instances with many courses the following call can be fatal, because each trigger
// check function will be called for every single course of the instance to determine how many
// courses will be triggered by the workflow/the specific trigger. This count is only being
// used to show the admin how many courses will be triggered, it has no functional aspect.
$amounts = (new \tool_lifecycle\processor())->get_count_of_courses_to_trigger_for_workflow($workflow->id);
$displaytotaltriggered = !empty($triggers);
}

foreach ($triggers as $trigger) {
// The array from the DB Function uses ids as keys.
Expand All @@ -108,11 +115,13 @@
);
}
$trigger->actionmenu = $OUTPUT->render($actionmenu);
$trigger->automatic = $amounts[$trigger->sortindex]->automatic;
$displaytotaltriggered &= $trigger->automatic;
if ($trigger->automatic) {
$trigger->triggeredcourses = $amounts[$trigger->sortindex]->triggered;
$trigger->excludedcourses = $amounts[$trigger->sortindex]->excluded;
if ($showcoursecounts) {
$trigger->automatic = $amounts[$trigger->sortindex]->automatic;
$displaytotaltriggered &= $trigger->automatic;
if ($trigger->automatic) {
$trigger->triggeredcourses = $amounts[$trigger->sortindex]->triggered;
$trigger->excludedcourses = $amounts[$trigger->sortindex]->excluded;
}
}
}

Expand Down Expand Up @@ -176,10 +185,11 @@
'finishdelay' => format_time($workflow->finishdelay),
'delayglobally' => $workflow->delayforallworkflows,
'trigger' => array_values($triggers),
'automatic' => $displaytotaltriggered,
'coursestriggered' => $amounts['all']->triggered,
'coursesexcluded' => $amounts['all']->excluded,
'coursesetsize' => $amounts['all']->coursesetsize,
'showcoursecounts' => $showcoursecounts,
'automatic' => $showcoursecounts ?? $displaytotaltriggered,
'coursestriggered' => $showcoursecounts ?? $amounts['all']->triggered,
'coursesexcluded' => $showcoursecounts ?? $amounts['all']->excluded,
'coursesetsize' => $showcoursecounts ?? $amounts['all']->coursesetsize,
'steps' => array_values($steps),
'listofcourses' => $arrayofcourses,
'nosteplink' => $nosteplink,
Expand Down

0 comments on commit 053d163

Please sign in to comment.