Skip to content

Commit

Permalink
Refactor getRealRowCountTable
Browse files Browse the repository at this point in the history
Signed-off-by: Liviu-Mihail Concioiu <[email protected]>
  • Loading branch information
liviuconcioiu committed Jan 18, 2025
1 parent 27a9838 commit a99534f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Controllers/Database/Structure/RealRowCountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __invoke(ServerRequest $request): Response
// If there is a request to update all table's row count.
if (! isset($parameters['real_row_count_all'])) {
// Get the real row count for the table.
$realRowCount = (int) $this->dbi
$realRowCount = $this->dbi
->getTable(Current::$database, (string) $parameters['table'])
->getRealRowCountTable();
// Format the number.
Expand All @@ -70,7 +70,7 @@ public function __invoke(ServerRequest $request): Response
$realRowCountAll = [];
// Iterate over each table and fetch real row count.
foreach ($this->dbi->getTables(Current::$database) as $table) {
$rowCount = (int) $this->dbi
$rowCount = $this->dbi
->getTable(Current::$database, $table)
->getRealRowCountTable();
$realRowCountAll[] = ['table' => $table, 'row_count' => Util::formatNumber($rowCount, 0)];
Expand Down
19 changes: 4 additions & 15 deletions src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1742,23 +1742,12 @@ public function showCreate(): string
/**
* Returns the real row count for a table
*/
public function getRealRowCountTable(): int|null
public function getRealRowCountTable(): int
{
// SQL query to get row count for a table.
$result = $this->dbi->fetchSingleRow(
sprintf(
'SELECT COUNT(*) AS %s FROM %s.%s',
Util::backquote('row_count'),
Util::backquote($this->dbName),
Util::backquote($this->name),
),
return (int) $this->dbi->fetchValue(
'SELECT COUNT(*) FROM ' . Util::backquote($this->dbName) . '.'
. Util::backquote($this->name)
);

if ($result === []) {
return null;
}

return (int) $result['row_count'];
}

/**
Expand Down

0 comments on commit a99534f

Please sign in to comment.