Skip to content
Merged
Changes from all 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
41 changes: 21 additions & 20 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,34 +284,35 @@ public function getSizeOfCollection(string $collection): int
$database = $this->getDatabase();
$permissions = $collection . '_perms';

$collectionSize = $this->getPDO()->prepare("
SELECT SUM(data_length + index_length)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = :name AND
table_schema = :database
");

$permissionsSize = $this->getPDO()->prepare("
SELECT SUM(data_length + index_length)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = :permissions AND
table_schema = :database
// Both tables in one round trip. Keep the equality predicates: LIKE and IN are
// not indexed here, they scan every table in the schema.
$statement = $this->getPDO()->prepare("
SELECT SUM(size) FROM (
SELECT data_length + index_length AS size
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = :name AND
table_schema = :database_name
UNION ALL
SELECT data_length + index_length AS size
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = :permissions AND
table_schema = :database_permissions
) AS sizes
");

$collectionSize->bindParam(':name', $collection);
$collectionSize->bindParam(':database', $database);
$permissionsSize->bindParam(':permissions', $permissions);
$permissionsSize->bindParam(':database', $database);
$statement->bindParam(':name', $collection);
$statement->bindParam(':permissions', $permissions);
$statement->bindParam(':database_name', $database);
$statement->bindParam(':database_permissions', $database);

try {
$collectionSize->execute();
$permissionsSize->execute();
$size = $collectionSize->fetchColumn() + $permissionsSize->fetchColumn();
$statement->execute();
$size = $statement->fetchColumn();
} catch (PDOException $e) {
throw new DatabaseException('Failed to get collection size: ' . $e->getMessage());
}

return $size;
return (int) $size;
}

/**
Expand Down
Loading