Skip to content

Commit 5198c9f

Browse files
james-johnston-thumbtackbarryvdh
authored andcommitted
Fix incorrect duplicate statement counter in PDO collector (php-debugbar#323)
The PDO collector assumes that the number of duplicate statements is equal to the number of total statements minus the number of unique statement query strings that had more than one query. This leads to non-sensical statements like the following: 5 statements were executed, 4 of which were duplicated, 1 unique when the following statements were executed. (Assume each letter represents a particular query) * A * A * B * C * D Clearly there are not 4 duplicate statements under any reasonable interpretation. After this code change, it would more correctly say for the above example: 5 statements were executed, 2 of which were duplicates, 3 unique
1 parent f8f5222 commit 5198c9f

File tree

1 file changed

+7
-5
lines changed
  • src/DebugBar/Resources/widgets/sqlqueries

1 file changed

+7
-5
lines changed

src/DebugBar/Resources/widgets/sqlqueries/widget.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
this.$status.empty();
9292

9393
// Search for duplicate statements.
94-
for (var sql = {}, unique = 0, i = 0; i < data.statements.length; i++) {
94+
for (var sql = {}, unique = 0, duplicate = 0, i = 0; i < data.statements.length; i++) {
9595
var stmt = data.statements[i].sql;
9696
if (data.statements[i].params && !$.isEmptyObject(data.statements[i].params)) {
9797
stmt += ' {' + $.param(data.statements[i].params, false) + '}';
@@ -102,20 +102,22 @@
102102
// Add classes to all duplicate SQL statements.
103103
for (var stmt in sql) {
104104
if (sql[stmt].keys.length > 1) {
105-
unique++;
105+
duplicate += sql[stmt].keys.length;
106106
for (var i = 0; i < sql[stmt].keys.length; i++) {
107107
this.$list.$el.find('.' + csscls('list-item')).eq(sql[stmt].keys[i])
108-
.addClass(csscls('sql-duplicate')).addClass(csscls('sql-duplicate-'+unique));
108+
.addClass(csscls('sql-duplicate'));
109109
}
110+
} else {
111+
unique++;
110112
}
111113
}
112114

113115
var t = $('<span />').text(data.nb_statements + " statements were executed").appendTo(this.$status);
114116
if (data.nb_failed_statements) {
115117
t.append(", " + data.nb_failed_statements + " of which failed");
116118
}
117-
if (unique) {
118-
t.append(", " + (data.nb_statements - unique) + " of which were duplicated");
119+
if (duplicate) {
120+
t.append(", " + duplicate + " of which were duplicates");
119121
t.append(", " + unique + " unique");
120122
}
121123
if (data.accumulated_duration_str) {

0 commit comments

Comments
 (0)