Skip to content

Commit be49aea

Browse files
authored
Issue catalyst#247: Reshuffle tabs (catalyst#251)
Improve breadcrumbs to display link to group list. Improve tabs to show active when displaying a group.
1 parent 2450cdf commit be49aea

10 files changed

+110
-109
lines changed

classes/grouped_profile_table.php

+31-7
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,40 @@ class grouped_profile_table extends profile_table {
3636
'minduration',
3737
];
3838

39+
/** @var \moodle_url $urlpath URL path to use for linking to profile groups. */
40+
protected $urlpath;
41+
3942
/**
40-
* Sets the SQL.
43+
* Set the URL path to use for linking to profile groups.
44+
*
45+
* @param \moodle_url $url
46+
*/
47+
public function set_url_path(\moodle_url $url) {
48+
$this->urlpath = $url;
49+
}
50+
51+
/**
52+
* Sets the SQL for the table.
4153
*/
4254
protected function put_sql(): void {
43-
global $DB;
4455

56+
list($filterstring, $filterparams) = $this->get_filter_for_sql();
57+
58+
$this->set_count_sql(
59+
"SELECT count(distinct request)
60+
FROM {tool_excimer_profiles}
61+
WHERE $filterstring",
62+
$filterparams
63+
);
64+
65+
$filterstring .= " GROUP BY groupby, scripttype";
4566
$this->set_sql(
4667
'groupby, count(request) as requestcount, scripttype, max(created) as maxcreated, min(created) as mincreated,
4768
max(duration) as maxduration, min(duration) as minduration',
4869
'{tool_excimer_profiles}',
49-
'1=1 GROUP BY groupby, scripttype'
70+
$filterstring,
71+
$filterparams
5072
);
51-
$this->set_count_sql("SELECT count(distinct request) FROM {tool_excimer_profiles}");
5273
}
5374

5475
/**
@@ -76,10 +97,13 @@ public function col_group(\stdClass $record): string {
7697
if ($this->is_downloading()) {
7798
return $displayedvalue;
7899
} else {
100+
$url = clone $this->urlpath;
101+
$url->param('group', $record->groupby);
79102
return \html_writer::link(
80-
new \moodle_url('/admin/tool/excimer/slowest.php', ['group' => $record->groupby]),
81-
shorten_text($displayedvalue, 100, true, ''),
82-
['title' => $displayedvalue, 'style' => 'word-break: break-all']);
103+
$url,
104+
shorten_text($displayedvalue, 100, true, ''),
105+
['title' => $displayedvalue, 'style' => 'word-break: break-all']
106+
);
83107
}
84108
}
85109

classes/output/tabs.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,15 @@ public function export_for_template(\renderer_base $output): array {
5151

5252
[
5353
'id' => 'slowest_web',
54-
'link' => [[ 'link' => new \moodle_url('/admin/tool/excimer/slowest.php') ]],
54+
'link' => [[ 'link' => new \moodle_url('/admin/tool/excimer/slowest_web.php') ]],
5555
'title' => get_string('report_slowest_web', 'tool_excimer'),
56-
'text' => get_string('slowest_web', 'tool_excimer'),
57-
],
58-
[
59-
'id' => 'slowest_grouped',
60-
'link' => [[ 'link' => new \moodle_url('/admin/tool/excimer/slowest_grouped.php') ]],
61-
'title' => get_string('report_slowest_grouped', 'tool_excimer'),
62-
'text' => get_string('slowest_grouped', 'tool_excimer'),
56+
'text' => get_string('tab_slowest_web', 'tool_excimer'),
6357
],
6458
[
6559
'id' => 'slowest_other',
6660
'link' => [[ 'link' => new \moodle_url('/admin/tool/excimer/slowest_other.php') ]],
6761
'title' => get_string('report_slowest_other', 'tool_excimer'),
68-
'text' => get_string('slowest_other', 'tool_excimer'),
62+
'text' => get_string('tab_slowest_other', 'tool_excimer'),
6963
],
7064
[
7165
'id' => 'recent',
@@ -83,7 +77,7 @@ public function export_for_template(\renderer_base $output): array {
8377
];
8478

8579
foreach ($tabs['tabs'] as &$tab) {
86-
if ($tab['link'][0]['link'] == $this->activeurl) {
80+
if ($tab['link'][0]['link']->get_path(false) == $this->activeurl->get_path(false)) {
8781
$tab['active'] = true;
8882
}
8983
}

classes/profile_table.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ protected function get_columns(): array {
112112
}
113113

114114
/**
115-
* Sets the SQL for the table.
115+
* Constructs a where clause for the filters.
116+
*
117+
* @return array - The filter string and parameters as a list.
116118
*/
117-
protected function put_sql(): void {
119+
protected function get_filter_for_sql(): array {
118120
global $DB;
119121

120-
$filterstring = '';
121122
$filter = [];
122123
$filterparams = [];
123124
if (count($this->filters)) {
@@ -135,6 +136,15 @@ protected function put_sql(): void {
135136
$filterstring .= " and scripttype $query";
136137
$filterparams = array_merge($filterparams, $params);
137138
}
139+
return [$filterstring, $filterparams];
140+
}
141+
142+
/**
143+
* Sets the SQL for the table.
144+
*/
145+
protected function put_sql(): void {
146+
147+
list($filterstring, $filterparams) = $this->get_filter_for_sql();
138148

139149
$fields = [
140150
'{tool_excimer_profiles}.id as id',

lang/en/tool_excimer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
// Admin Tree.
3232
$string['report_slowest'] = 'Slowest profiles';
3333
$string['report_slowest_grouped'] = 'Slowest scripts';
34-
$string['report_slowest_web'] = 'Slowest web';
35-
$string['report_slowest_other'] = 'Slowest other';
34+
$string['report_slowest_web'] = 'Slow web pages';
35+
$string['report_slowest_other'] = 'Slow tasks/CLI/WS';
3636
$string['report_recent'] = 'Recently profiled';
3737
$string['report_unfinished'] = 'Currently profiling';
3838

@@ -80,8 +80,8 @@
8080
$string['slowest_grouped'] = 'Slowest scripts';
8181
$string['recent'] = 'Recent';
8282
$string['slowest'] = 'Slowest';
83-
$string['slowest_web'] = 'Slowest web';
84-
$string['slowest_other'] = 'Slowest other';
83+
$string['tab_slowest_web'] = 'Slow web pages';
84+
$string['tab_slowest_other'] = 'Slow tasks/CLI/WS';
8585
$string['unfinished'] = 'Unfinished';
8686

8787
// Profile table.

profile.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@
3333
/** Report section - recent - lists the most recent profiles first */
3434
const REPORT_SECTION_RECENT = 'recent';
3535

36-
/** Report section - slowest - lists the slowest profiles first */
37-
const REPORT_SECTION_SLOWEST = 'slowest';
36+
/** Report section - slowest web - lists profile groups for web pages. */
37+
const REPORT_SECTION_SLOWEST_WEB = 'slowest_web';
38+
39+
/** Report section - slowest other - lists profile groups for tasks, CLI and WS scripts. */
40+
const REPORT_SECTION_SLOWEST_OTHER = 'slowest_other';
3841

3942
/** Report section - unfinished - lists profiles of scripts that did not finish */
4043
const REPORT_SECTION_UNFINISHED = 'unfinished';
4144

4245
/** Report sections */
4346
const REPORT_SECTIONS = [
4447
REPORT_SECTION_RECENT,
45-
REPORT_SECTION_SLOWEST,
48+
REPORT_SECTION_SLOWEST_WEB,
49+
REPORT_SECTION_SLOWEST_OTHER,
4650
REPORT_SECTION_UNFINISHED,
4751
];
4852

@@ -57,11 +61,11 @@
5761

5862
$returnurl = get_local_referer(false);
5963

60-
// The page's breadcrumb will include a link to the reports for recent or slowest (default).
64+
// The page's breadcrumb will include a link to the top level report pages that are defined by the tabs.
6165
// Handling here prevents things links from other pages and paginated listings
6266
// from breaking the output of this page.
6367
$report = explode('.php', basename($returnurl, '.php'))[0] ?? null;
64-
$report = in_array($report, REPORT_SECTIONS) ? $report : REPORT_SECTION_SLOWEST;
68+
$report = in_array($report, REPORT_SECTIONS) ? $report : REPORT_SECTION_SLOWEST_WEB;
6569
admin_externalpage_setup('tool_excimer_report_' . $report);
6670

6771
$output = $PAGE->get_renderer('tool_excimer');
@@ -72,6 +76,9 @@
7276

7377
$profile = new profile($profileid);
7478

79+
$prevurl = new moodle_url('/admin/tool/excimer/' . $report. '.php', ['group' => $profile->get('groupby')]);
80+
$PAGE->navbar->add($profile->get('groupby'), $prevurl);
81+
7582
$PAGE->navbar->add($profile->get('request') . $profile->get('pathinfo'));
7683
$PAGE->set_title($pluginname);
7784
$PAGE->set_pagelayout('admin');

settings.php

+2-15
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
)
112112
);
113113

114-
115114
$settings->add(
116115
new admin_setting_configduration(
117116
'tool_excimer/expiry_s',
@@ -156,7 +155,6 @@
156155
$item->set_updatedcallback($clearprofiletimingscachecallback);
157156
$settings->add($item);
158157

159-
160158
$item = new admin_setting_configtext(
161159
'tool_excimer/num_slowest',
162160
get_string('num_slowest', 'tool_excimer'),
@@ -179,23 +177,12 @@
179177

180178
}
181179

182-
183180
$ADMIN->add(
184181
'tool_excimer_reports',
185182
new admin_externalpage(
186-
'tool_excimer_report_slowest',
183+
'tool_excimer_report_slowest_web',
187184
get_string('report_slowest_web', 'tool_excimer'),
188-
new moodle_url('/admin/tool/excimer/slowest.php'),
189-
'moodle/site:config'
190-
)
191-
);
192-
193-
$ADMIN->add(
194-
'tool_excimer_reports',
195-
new admin_externalpage(
196-
'tool_excimer_report_slowest_grouped',
197-
get_string('report_slowest_grouped', 'tool_excimer'),
198-
new moodle_url('/admin/tool/excimer/slowest_grouped.php'),
185+
new moodle_url('/admin/tool/excimer/slowest_web.php'),
199186
'moodle/site:config'
200187
)
201188
);

slowest_grouped.php

-39
This file was deleted.

slowest_other.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26+
use tool_excimer\grouped_profile_table;
2627
use tool_excimer\profile;
2728
use tool_excimer\profile_table;
2829
use tool_excimer\profile_table_page;
@@ -39,16 +40,24 @@
3940

4041
$url = new moodle_url("/admin/tool/excimer/slowest_other.php");
4142

42-
$table = new profile_table('profile_table_slowest_other');
43-
$table->set_scripttypes([profile::SCRIPTTYPE_CLI, profile::SCRIPTTYPE_TASK, profile::SCRIPTTYPE_WS]);
44-
$table->sortable(true, 'duration', SORT_DESC);
45-
if ($script) {
46-
$table->add_filter('request', $script);
47-
$url->params(['script' => $script]);
48-
}
49-
if ($group) {
50-
$table->add_filter('groupby', $group);
51-
$url->params(['group' => $group]);
43+
if ($script || $group) {
44+
$table = new profile_table('profile_table_slowest_other');
45+
$table->sortable(true, 'duration', SORT_DESC);
46+
if ($script) {
47+
$table->add_filter('request', $script);
48+
$url->params(['script' => $script]);
49+
}
50+
if ($group) {
51+
$table->add_filter('groupby', $group);
52+
$url->params(['group' => $group]);
53+
$PAGE->navbar->add($group);
54+
}
55+
} else {
56+
$table = new grouped_profile_table('profile_table_slowest_other');
57+
$table->set_url_path($url);
58+
$table->sortable(true, 'maxduration', SORT_DESC);
5259
}
5360

61+
$table->set_scripttypes([profile::SCRIPTTYPE_CLI, profile::SCRIPTTYPE_TASK, profile::SCRIPTTYPE_WS]);
62+
5463
profile_table_page::display($table, $url);

slowest.php slowest_web.php

+23-14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26+
use tool_excimer\grouped_profile_table;
2627
use tool_excimer\profile;
2728
use tool_excimer\profile_table;
2829
use tool_excimer\profile_table_page;
@@ -35,20 +36,28 @@
3536
$script = optional_param('script', '', PARAM_TEXT);
3637
$group = optional_param('group', '', PARAM_TEXT);
3738

38-
admin_externalpage_setup('tool_excimer_report_slowest');
39-
40-
$url = new moodle_url("/admin/tool/excimer/slowest.php");
41-
42-
$table = new profile_table('profile_table_slowest');
43-
$table->set_scripttypes([profile::SCRIPTTYPE_WEB, profile::SCRIPTTYPE_AJAX]);
44-
$table->sortable(true, 'duration', SORT_DESC);
45-
if ($script) {
46-
$table->add_filter('request', $script);
47-
$url->params(['script' => $script]);
48-
}
49-
if ($group) {
50-
$table->add_filter('groupby', $group);
51-
$url->params(['group' => $group]);
39+
admin_externalpage_setup('tool_excimer_report_slowest_web');
40+
41+
$url = new moodle_url('/admin/tool/excimer/slowest_web.php');
42+
43+
if ($script || $group) {
44+
$table = new profile_table('profile_table_slowest_web');
45+
$table->sortable(true, 'duration', SORT_DESC);
46+
if ($script) {
47+
$table->add_filter('request', $script);
48+
$url->params(['script' => $script]);
49+
}
50+
if ($group) {
51+
$table->add_filter('groupby', $group);
52+
$url->params(['group' => $group]);
53+
$PAGE->navbar->add($group);
54+
}
55+
} else {
56+
$table = new grouped_profile_table('profile_table_slowest_web');
57+
$table->set_url_path($url);
58+
$table->sortable(true, 'maxduration', SORT_DESC);
5259
}
5360

61+
$table->set_scripttypes([profile::SCRIPTTYPE_WEB]);
62+
5463
profile_table_page::display($table, $url);

version.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2022050600;
29-
$plugin->release = 2022050600;
28+
$plugin->version = 2022083100;
29+
$plugin->release = 2022083100;
3030

3131
$plugin->requires = 2017051500; // Moodle 3.3 for Totara support.
3232

0 commit comments

Comments
 (0)