From 7ed8f13a4932edb36f31ccb4d8e2ae5800784c3f Mon Sep 17 00:00:00 2001 From: Joshua Jabbour Date: Mon, 24 Mar 2014 22:54:11 -0700 Subject: [PATCH 1/5] Add classes to all duplicate SQL statement rows. --- .../Resources/widgets/sqlqueries/widget.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/DebugBar/Resources/widgets/sqlqueries/widget.js b/src/DebugBar/Resources/widgets/sqlqueries/widget.js index e092bdb..5a9f61d 100644 --- a/src/DebugBar/Resources/widgets/sqlqueries/widget.js +++ b/src/DebugBar/Resources/widgets/sqlqueries/widget.js @@ -53,10 +53,30 @@ this.$list.set('data', data.statements); this.$status.empty(); + // Search for duplicate statements. + for (var sql = {}, duplicate = 0, i = 0; i < data.statements.length; i++) { + var stmt = data.statements[i].sql; + sql[stmt] = sql[stmt] || { keys: [] }; + sql[stmt].keys.push(i); + } + // Add classes to all duplicate SQL statements. + for (var stmt in sql) { + if (sql[stmt].keys.length > 1) { + duplicate++; + for (var i = 0; i < sql[stmt].keys.length; i++) { + this.$list.$el.find('.' + csscls('list-item')).eq(sql[stmt].keys[i]) + .addClass(csscls('sql-duplicate')).addClass(csscls('sql-duplicate-'+duplicate)); + } + } + } + var t = $('').text(data.nb_statements + " statements were executed").appendTo(this.$status); if (data.nb_failed_statements) { t.append(", " + data.nb_failed_statements + " of which failed"); } + if (duplicate) { + t.append(", " + duplicate + " of which were duplicates"); + } if (data.accumulated_duration_str) { this.$status.append($('').addClass(csscls('duration')).text(data.accumulated_duration_str)); } From b88a773183cf7f9eaae3ebcabbbe84bc6ed42bfd Mon Sep 17 00:00:00 2001 From: Joshua Jabbour Date: Mon, 24 Mar 2014 22:57:13 -0700 Subject: [PATCH 2/5] Highlight duplicate SQL statements. --- src/DebugBar/Resources/widgets/sqlqueries/widget.css | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/DebugBar/Resources/widgets/sqlqueries/widget.css b/src/DebugBar/Resources/widgets/sqlqueries/widget.css index 8bc5d36..ea4be61 100644 --- a/src/DebugBar/Resources/widgets/sqlqueries/widget.css +++ b/src/DebugBar/Resources/widgets/sqlqueries/widget.css @@ -1,4 +1,3 @@ - div.phpdebugbar-widgets-sqlqueries .phpdebugbar-widgets-status { font-family: monospace; padding: 6px 6px; @@ -66,4 +65,8 @@ div.phpdebugbar-widgets-sqlqueries table.phpdebugbar-widgets-params { div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item span.phpdebugbar-widgets-error { display: block; font-weight: bold; -} \ No newline at end of file +} + +div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-duplicate { + background-color: #ffc; +} From 168da436d1176e33b0875d52609453589677e4c7 Mon Sep 17 00:00:00 2001 From: Joshua Jabbour Date: Mon, 24 Mar 2014 23:25:42 -0700 Subject: [PATCH 3/5] Update duplicate query bg color to add hover state. --- src/DebugBar/Resources/widgets/sqlqueries/widget.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DebugBar/Resources/widgets/sqlqueries/widget.css b/src/DebugBar/Resources/widgets/sqlqueries/widget.css index ea4be61..5d97b7f 100644 --- a/src/DebugBar/Resources/widgets/sqlqueries/widget.css +++ b/src/DebugBar/Resources/widgets/sqlqueries/widget.css @@ -68,5 +68,9 @@ div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item span.phpdebu } div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-duplicate { + background-color: #ffd; +} + +div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-duplicate:hover { background-color: #ffc; } From 36d99d43d82b678c498837526db069b180bfcc9f Mon Sep 17 00:00:00 2001 From: Joshua Jabbour Date: Mon, 24 Mar 2014 23:27:21 -0700 Subject: [PATCH 4/5] Update duplicated status message to follow pattern. --- src/DebugBar/Resources/widgets/sqlqueries/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DebugBar/Resources/widgets/sqlqueries/widget.js b/src/DebugBar/Resources/widgets/sqlqueries/widget.js index 5a9f61d..1c1222b 100644 --- a/src/DebugBar/Resources/widgets/sqlqueries/widget.js +++ b/src/DebugBar/Resources/widgets/sqlqueries/widget.js @@ -75,7 +75,7 @@ t.append(", " + data.nb_failed_statements + " of which failed"); } if (duplicate) { - t.append(", " + duplicate + " of which were duplicates"); + t.append(", " + duplicate + " of which were duplicated"); } if (data.accumulated_duration_str) { this.$status.append($('').addClass(csscls('duration')).text(data.accumulated_duration_str)); From 7c0c9c7043d6d4010df9cc8d56e76eeef92d55bf Mon Sep 17 00:00:00 2001 From: Joshua Jabbour Date: Mon, 24 Mar 2014 23:43:50 -0700 Subject: [PATCH 5/5] Include params object when counting query duplicates. --- src/DebugBar/Resources/widgets/sqlqueries/widget.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/DebugBar/Resources/widgets/sqlqueries/widget.js b/src/DebugBar/Resources/widgets/sqlqueries/widget.js index 1c1222b..f849fee 100644 --- a/src/DebugBar/Resources/widgets/sqlqueries/widget.js +++ b/src/DebugBar/Resources/widgets/sqlqueries/widget.js @@ -56,6 +56,9 @@ // Search for duplicate statements. for (var sql = {}, duplicate = 0, i = 0; i < data.statements.length; i++) { var stmt = data.statements[i].sql; + if (data.statements[i].params && !$.isEmptyObject(data.statements[i].params)) { + stmt += ' {' + $.param(data.statements[i].params, false) + '}'; + } sql[stmt] = sql[stmt] || { keys: [] }; sql[stmt].keys.push(i); }