yiisoft / yii2-debug

Debug Extension for Yii 2
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
202 stars 149 forks source link

DB summary view uses $criticalQueryThreshold directly instead of checking via isQueryCountCritical() method #505

Closed MarkoNV closed 1 year ago

MarkoNV commented 1 year ago

What steps will reproduce the problem?

Keep default configuration without setting $criticalQueryThreshold. Make request with at least one DB query.

What's expected?

Since $criticalQueryThreshold is unset, no warning is shown on /debug/default/index nor at DB panel's title

What do you get instead?

/debug/default/index omits warning, but DB panel's title shows warning with message: "Executed 9 database queries which took 6 ms. Too many queries, allowed count is ."

Additional info

/vendor/yiisoft/yii2-debug/src/views/default/index.php makes check via isQueryCountCritical() method :

if ($dbPanel->isQueryCountCritical($data['sqlCount'])) {
    $title .= ' 
Too many queries. Allowed count is ' . $dbPanel->criticalQueryThreshold;
    $hasError = true;
}

But, /vendor/yiisoft/yii2-debug/src/views/default/panels/db/summary.php accesses $criticalQueryThreshold directly, without checking if it's set:

if ($queryCount >= $panel->criticalQueryThreshold) {
    $title .= " 
Too many queries, allowed count is {$panel->criticalQueryThreshold}.";
    $hasError = true;
}

It should be updated to:

if ($panel->isQueryCountCritical($queryCount)) {
    $title .= " 
Too many queries, allowed count is {$panel->criticalQueryThreshold}.";
    $hasError = true;
}

to use same isset logic as listing page.

Q A
Yii version ~2.0.13
Yii debug version 2.1.23
PHP version Tested 7.4 & 8.1
Operating system Tested on Ubuntu
samdark commented 1 year ago

@rhertogh ?

rhertogh commented 1 year ago

@samdark PR: #506