Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug toolbar db connection count #5172

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Database extends BaseCollector
*/
protected static $queries = [];

/**
* Array of connections used in a collected set
* of queries.
*
* @var array
*/
protected static $activeConnections = [];

/**
* Constructor
*/
Expand All @@ -83,6 +91,12 @@ public static function collect(Query $query)
$max = $config->maxQueries ?: 100;

if (count(static::$queries) < $max) {
$connection = $query->db->getDatabase();

if (! in_array($connection, self::$activeConnections, true)) {
self::$activeConnections[] = $connection;
}

static::$queries[] = $query;
}
}
Expand Down Expand Up @@ -148,8 +162,16 @@ public function getBadgeValue(): int
*/
public function getTitleDetails(): string
{
return '(' . count(static::$queries) . ' Queries across ' . ($countConnection = count($this->connections)) . ' Connection' .
($countConnection > 1 ? 's' : '') . ')';
$queryCount = count(static::$queries);
$connectionCount = count(static::$activeConnections);

return sprintf(
'(%d Quer%s across %d Connection%s)',
$queryCount,
$queryCount > 1 ? 'ies' : 'y',
$connectionCount,
$connectionCount > 1 ? 's' : ''
);
}

/**
Expand Down