Skip to content

Commit 23a8455

Browse files
committed
Switch the datatable view to be a ajax pull rather then a load everything on page load. This speeds up initial page load significantly. Some other misc improvements. Setting to allow you to disable query syntax highlighting.
1 parent 8c41a61 commit 23a8455

File tree

9 files changed

+281
-120
lines changed

9 files changed

+281
-120
lines changed

config.php.example

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
// Settings
3+
4+
// Syntax highlight queries?
5+
$settings['sqlColor'] = true;
26

37
$reviewhost = array(
48
// Replace hostname and database in this setting
@@ -8,6 +12,7 @@ $reviewhost = array(
812
// See http://www.percona.com/doc/percona-toolkit/2.0/pt-query-digest.html#cmdoption-pt-query-digest--review
913
'review_table' => 'review',
1014
// This table is optional. You don't need it, but you lose detailed stats
15+
// Set to a blank string to disable
1116
// See http://www.percona.com/doc/percona-toolkit/2.0/pt-query-digest.html#cmdoption-pt-query-digest--review-history
1217
'history_table' => 'review_history',
1318
);

css/style.css

+19-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
}
1111

1212
#Queries_processing {
13-
padding-left: 1em;
13+
width: 8em;
14+
margin-left: auto;
15+
margin-right: auto;
1416
}
1517

1618
.fg-toolbar {
17-
padding-top: .5em;
18-
padding-bottom: .5em;
19+
padding-top: .25em;
20+
padding-bottom: .25em;
1921
}
2022

2123
#Queries_info {
@@ -99,3 +101,17 @@ a.column {
99101
color: #000066;
100102
cursor: pointer;
101103
}
104+
105+
#Queries {
106+
width: 100% !important;
107+
margin-left: -2px;
108+
}
109+
110+
.details {
111+
width: 20px;
112+
padding: 2px;
113+
}
114+
115+
.fingerprint {
116+
width: 100%;
117+
}

explain.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require('init.php');
3+
require_once('init.php');
44

55
$return = array();
66

@@ -16,7 +16,7 @@
1616

1717
list($label, $database) = explode('.', $_REQUEST['explainDb']);
1818
$host = $explainhosts[$label];
19-
$ebh = new PDO($host['dsn'], $host['user'], $host['password']);
19+
$ebh = new PDO($host['dsn'], $host['user'], $host['password'], array( PDO::ATTR_PERSISTENT => true ));
2020

2121
$query = $ebh->prepare("USE $database");
2222
$query->execute();

index.php

+55-83
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,16 @@
11
<?php
2+
require_once('init.php');
23

3-
require('init.php');
44

5-
if (strlen($reviewhost['history_table'])) {
6-
$list = $dbh->prepare('SELECT review.checksum AS checksum,
7-
review.fingerprint AS fingerprint,
5+
$users = $dbh->query('SELECT DISTINCT IFNULL(reviewed_by, "") FROM '.$reviewhost['review_table']);
6+
$Reviewers = "[ 'None' ";
7+
while($user = $users->fetchColumn())
8+
$Reviewers .= ",'$user' ";
9+
$Reviewers .= " ]";
10+
unset($users);
811

9-
DATE(review.first_seen) AS first_seen,
10-
DATE(review.last_seen) AS last_seen,
11-
IFNULL(review.reviewed_by, "-") AS reviewed_by,
12-
DATE(review.reviewed_on) AS reviewed_on,
13-
review.comments AS comments,
1412

15-
SUM(history.ts_cnt) AS count,
16-
ROUND(SUM(history.query_time_sum), 2) AS time,
17-
ROUND(SUM(history.query_time_sum)/SUM(history.ts_cnt), 2) AS time_avg
18-
19-
FROM '.$reviewhost['review_table'].' AS review
20-
LEFT JOIN '.$reviewhost['history_table'].' AS history
21-
ON history.checksum = review.checksum
22-
GROUP BY review.checksum
23-
');
24-
}
25-
else {
26-
$list = $dbh->prepare('SELECT review.checksum AS checksum,
27-
review.fingerprint AS fingerprint,
28-
29-
DATE(review.first_seen) AS first_seen,
30-
DATE(review.last_seen) AS last_seen,
31-
IFNULL(review.reviewed_by, "-") AS reviewed_by,
32-
DATE(review.reviewed_on) AS reviewed_on,
33-
review.comments AS comments,
34-
35-
0 AS count,
36-
0 AS time,
37-
0 AS time_avg
38-
39-
FROM '.$reviewhost['review_table'].' AS review
40-
GROUP BY review.checksum
41-
');
42-
}
43-
$list->execute();
44-
include('templates/header.php');
13+
require_once('templates/header.php');
4514
?>
4615

4716
<table id="Queries">
@@ -60,37 +29,19 @@
6029
</tr>
6130
</thead>
6231
<tbody>
63-
<?php
64-
while ($row = $list->fetch(PDO::FETCH_ASSOC)) {
65-
echo "<tr>";
66-
echo "<td class='count number'>".$row['count']."</td>";
67-
echo "<td class='time number'>".$row['time']."</td>";
68-
echo "<td class='avgTime number'>".$row['time_avg']."</td>";
69-
echo "<td class='firstSeen date'>".$row['first_seen']."</td>";
70-
echo "<td class='lastSeen date'>".$row['last_seen']."</td>";
71-
echo "<td class='fingerprint'>".SqlParser::htmlPreparedStatement($row['fingerprint'], true)."</td>";
72-
//echo "<td class='fingerprint'>".$row['fingerprint']."</td>";
73-
echo "<td class='reviewed_on'>".$row['reviewed_on']."</td>";
74-
echo "<td class='reviewed_by'>".$row['reviewed_by']."</td>";
75-
echo "<td class='comments'>".$row['comments']."</td>";
76-
77-
echo '<td class="details"><a class="details" href="review.php?checksum='.$row['checksum'].'"><img src="images/details_open.png"></a></td>';
78-
echo "</tr>";
79-
}
80-
?>
8132
</tbody>
8233
<tfoot>
8334
<tr>
84-
<th></th>
85-
<th></th>
86-
<th></th>
87-
<th></th>
88-
<th></th>
89-
<th></th>
90-
<th></th>
91-
<th></th>
92-
<th></th>
93-
<th></th>
35+
<th class="number"></th>
36+
<th class="number"></th>
37+
<th class="number"></th>
38+
<th class="date"></th>
39+
<th class="date"></th>
40+
<th class=""></th>
41+
<th class="date"></th>
42+
<th class=""></th>
43+
<th class=""></th>
44+
<th class=""></th>
9445
</tr>
9546
</tfoot>
9647
</table>
@@ -99,41 +50,58 @@
9950
$(function() {
10051

10152
oTable = $('#Queries').dataTable({
102-
"sDom": '"R<"H"rCp>t<"F"il>"',
53+
"bDeferRender": true,
54+
"bServerSide": true,
55+
"sAjaxSource": "list-ajax.php",
56+
"sDom": '"R<"H"Cpr>t<"F"il>"',
10357
"bJQueryUI": true,
10458
"bStateSave": true,
10559
// Store the cookie for one year
10660
"iCookieDuration": 31556926,
107-
"bProcessing": false,
61+
"bProcessing": true,
10862
"aaSort": [],
63+
"bAutoWidth": true,
10964
"aoColumnDefs": [
110-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 0 ] },
111-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 1 ] },
112-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 2 ] },
113-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 3 ] },
114-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 4 ] },
115-
{ "bSearchable": true, "bVisible": true, "aTargets": [ 5 ] },
116-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 6 ] },
117-
{ "bSearchable": true, "bVisible": true, "aTargets": [ 7 ] },
118-
{ "bSearchable": true, "bVisible": true, "aTargets": [ 8 ] },
119-
{ "bSearchable": false, "bVisible": true, "aTargets": [ 9 ], "bSortable": false }
65+
{ "sClass": "count number", "bSearchable": false, "bVisible": true, "aTargets": [ 0 ] },
66+
{ "sClass": "time number", "bSearchable": false, "bVisible": true, "aTargets": [ 1 ] },
67+
{ "sClass": "avgTime number", "bSearchable": false, "bVisible": true, "aTargets": [ 2 ] },
68+
{ "sClass": "firstSeen date", "bSearchable": false, "bVisible": true, "aTargets": [ 3 ] },
69+
{ "sClass": "lastSeen date", "bSearchable": false, "bVisible": true, "aTargets": [ 4 ] },
70+
{ "sClass": "fingerprint", "bSearchable": true, "bVisible": true, "aTargets": [ 5 ] },
71+
{ "sClass": "reviewed_on date", "bSearchable": false, "bVisible": true, "aTargets": [ 6 ] },
72+
{ "sClass": "reviewed_by", "bSearchable": true, "bVisible": true, "aTargets": [ 7 ] },
73+
{ "sClass": "comments", "bSearchable": true, "bVisible": true, "aTargets": [ 8 ] },
74+
{ "sClass": "details", "bSearchable": false, "bVisible": true, "aTargets": [ 9 ], "bSortable": false }
12075
],
12176
"oColVis": {
12277
"aiExclude": [ 9 ]
12378
},
124-
"fnStateSaveParams": function(oSettings, oData) {
79+
"fnDrawCallback" : function() {
80+
$("a.details").fancybox({
81+
type: 'iframe',
82+
width: '98%',
83+
height: '98%',
84+
centerOnScroll: true,
85+
padding: 0,
86+
margin: 10
87+
});
88+
return true;
89+
},
90+
"fnStateSaveCallback": function(oSettings, oData) {
12591
oData.aoSearchCols = [];
12692
oData.oFilter = [];
12793
oData.oSearch = [];
94+
return true;
12895
},
129-
"fnStateLoadParams": function(oSettings, oData) {
96+
"fnStateLoadCallback": function(oSettings, oData) {
13097
oData.aoSearchCols = [];
13198
oData.oFilter = [];
13299
oData.oSearch = [];
133100
oldVis = [];
134101
if (typeof oData.abVisCols == "object")
135102
oldVis = oData.abVisCols;
136103
oData.abVisCols = [];
104+
return true;
137105
}
138106
}).columnFilter({
139107
bUseColVis: true,
@@ -146,7 +114,7 @@
146114
{ type: "date-range" },
147115
{ type: "text" },
148116
{ type: "date-range" },
149-
{ type: "select" },
117+
{ type: "select", values: <?php echo $Reviewers; ?> },
150118
{ type: "text" },
151119
null
152120
]
@@ -159,8 +127,12 @@
159127
if (oldVis.length == oTable.fnSettings().aoColumns.length)
160128
for (var i=0; i < oldVis.length; i++)
161129
oTable.fnSetColumnVis(i, oldVis[i]);
130+
131+
$(window).bind('resize', function () {
132+
oTable.fnAdjustColumnSizing();
133+
} );
162134
});
163135
</script>
164136

165137
<?php
166-
include('templates/footer.php');
138+
require_once('templates/footer.php');

init.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
<?php
22

3-
require('config.php');
3+
// Set default settings here. Can be overridden in config.php.
4+
$settings = array();
5+
$settings['sqlColor'] = true;
46

5-
$dbh = new PDO($reviewhost['dsn'], $reviewhost['user'], $reviewhost['password']);
7+
require_once('config.php');
68

7-
unset($query);
9+
$dbh = new PDO($reviewhost['dsn'], $reviewhost['user'], $reviewhost['password'], array( PDO::ATTR_PERSISTENT => true ));
810

9-
foreach ($explainhosts as $label => $host) {
10-
if (!key_exists('databases', $explainhosts[$label]) || !count($explainhosts[$label]['databases'])) {
11-
$ebh = new PDO($host['dsn'], $host['user'], $host['password']);
12-
$query = $ebh->prepare('SHOW DATABASES');
13-
$query->execute();
14-
while (list($database) = $query->fetch(PDO::FETCH_NUM))
15-
$explainhosts[$label]['databases'][] = $database;
16-
$query->closeCursor();
17-
unset($ebh);
18-
}
19-
}
20-
21-
require('libs/sqlquery/SqlParser.php');
11+
require_once('libs/sqlquery/SqlParser.php');

libs/sqlquery/SqlParser.php

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ private static function trim($_array)
5050
}
5151

5252
public static function htmlPreparedStatement($_sql, $removeNewLines = false) {
53+
global $settings;
54+
if (!$settings['sqlColor'])
55+
return $_sql;
5356
try {
5457
$_sql = PMA_SQP_formatHtml(self::parsePreparedStatement($_sql));
5558
if ($removeNewLines) {
@@ -64,6 +67,9 @@ public static function htmlPreparedStatement($_sql, $removeNewLines = false) {
6467
}
6568

6669
public static function html($_sql, $removeNewLines = false) {
70+
global $settings;
71+
if (!$settings['sqlColor'])
72+
return $_sql;
6773
try {
6874
$_sql = PMA_SQP_formatHtml(self::parsePMA($_sql));
6975
if ($removeNewLines) {

0 commit comments

Comments
 (0)