Skip to content

Commit aa408a9

Browse files
committed
Move Schema::getConnectionsCount to Connection::getThreadsCount
1 parent f1e2205 commit aa408a9

18 files changed

+67
-59
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,18 @@ public function raw($value)
10841084
return new Expression($value);
10851085
}
10861086

1087+
/**
1088+
* Get the number of open connections for a database.
1089+
*
1090+
* @return int|null
1091+
*/
1092+
public function getThreadsCount()
1093+
{
1094+
$query = $this->getQueryGrammar()->compileThreadsCount();
1095+
1096+
return $query ? $this->scalar($query) : null;
1097+
}
1098+
10871099
/**
10881100
* Escape a value for safe SQL embedding.
10891101
*

src/Illuminate/Database/Console/DatabaseInspectionCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Database\Console;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Database\Connection;
67
use Illuminate\Database\ConnectionInterface;
78
use Illuminate\Support\Arr;
89

@@ -15,7 +16,7 @@ abstract class DatabaseInspectionCommand extends Command
1516
* @param string $database
1617
* @return string
1718
*
18-
* @deprecated Use $connection->getDriverTitle() instead.
19+
* @deprecated
1920
*/
2021
protected function getConnectionName(ConnectionInterface $connection, $database)
2122
{
@@ -28,11 +29,11 @@ protected function getConnectionName(ConnectionInterface $connection, $database)
2829
* @param \Illuminate\Database\ConnectionInterface $connection
2930
* @return int|null
3031
*
31-
* @deprecated Use Schema\Builder::getConnectionsCount() instead.
32+
* @deprecated
3233
*/
3334
protected function getConnectionCount(ConnectionInterface $connection)
3435
{
35-
return $connection->getSchemaBuilder()->getConnectionsCount();
36+
return $connection->getThreadsCount();
3637
}
3738

3839
/**

src/Illuminate/Database/Console/MonitorCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ protected function parseDatabases($databases)
8484
}
8585

8686
$maxConnections = $this->option('max');
87-
$connections = $this->connection->connection($database)->getSchemaBuilder()->getConnectionsCount();
87+
88+
$connections = $this->connection->connection($database)->getThreadsCount();
8889

8990
return [
9091
'database' => $database,

src/Illuminate/Database/Console/ShowCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(ConnectionResolverInterface $connections)
4848
'name' => $connection->getDriverTitle(),
4949
'connection' => $connection->getName(),
5050
'version' => $connection->getServerVersion(),
51-
'open_connections' => $schema->getConnectionsCount(),
51+
'open_connections' => $connection->getThreadsCount(),
5252
],
5353
'tables' => $this->tables($connection, $schema),
5454
];

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,4 +1564,14 @@ public function getBitwiseOperators()
15641564
{
15651565
return $this->bitwiseOperators;
15661566
}
1567+
1568+
/**
1569+
* Get the number of open connections for a database.
1570+
*
1571+
* @return string|null
1572+
*/
1573+
public function compileThreadsCount()
1574+
{
1575+
return null;
1576+
}
15671577
}

src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public function useLegacyGroupLimit(Builder $query)
4343
{
4444
return false;
4545
}
46+
47+
public function compileThreadsCount()
48+
{
49+
return 'select variable_value as `Value` from information_schema.global_status where variable_name = \'THREADS_CONNECTED\'';
50+
}
4651
}

src/Illuminate/Database/Query/Grammars/MySqlGrammar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,9 @@ protected function wrapJsonBooleanSelector($value)
514514

515515
return 'json_extract('.$field.$path.')';
516516
}
517+
518+
public function compileThreadsCount()
519+
{
520+
return 'select variable_value as `Value` from performance_schema.session_status where variable_name = \'threads_connected\'';
521+
}
517522
}

src/Illuminate/Database/Query/Grammars/PostgresGrammar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,9 @@ public function substituteBindingsIntoRawSql($sql, $bindings)
762762

763763
return $query;
764764
}
765+
766+
public function compileThreadsCount()
767+
{
768+
return 'select count(*) as "Value" from pg_stat_activity';
769+
}
765770
}

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ public function compileSavepointRollBack($name)
497497
return 'ROLLBACK TRANSACTION '.$name;
498498
}
499499

500+
public function compileThreadsCount()
501+
{
502+
return 'select count(*) Value from sys.dm_exec_sessions where status = N\'running\'';
503+
}
504+
500505
/**
501506
* Get the format for database stored dates.
502507
*

src/Illuminate/Database/Schema/Builder.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,19 +606,6 @@ public function setConnection(Connection $connection)
606606

607607
return $this;
608608
}
609-
610-
/**
611-
* Get the number of open connections for a database.
612-
*
613-
* @return int|null
614-
*/
615-
public function getConnectionsCount()
616-
{
617-
$query = $this->grammar->compileConnectionsCount();
618-
619-
return $query ? $this->connection->scalar($query) : null;
620-
}
621-
622609
/**
623610
* Set the Schema Blueprint resolver callback.
624611
*

0 commit comments

Comments
 (0)