Skip to content

Commit

Permalink
#8700 Updated countRecords() to use the Builder::safeCount()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed May 23, 2024
1 parent 9d9fad4 commit fe5ee56
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions classes/db/DAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ function retrieveRange($sql, $params = [], $dbResultRange = null, $callHooks = t
public function countRecords($sql, $params = []) {
// In case a Laravel Builder has been received, drop its SELECT and ORDER BY clauses for optimization purposes
if ($sql instanceof Builder) {
// Clone query to avoid side-effects
/** @var Builder */
$builder = clone $sql;
// Discard the SELECT and ORDER BY clauses
$builder->select(Capsule::raw('0'))->reorder();
$params = $builder->getBindings();
$sql = $builder->toSql();
return $sql->safeCount();
}
$result = $this->retrieve('SELECT COUNT(*) AS row_count FROM (' . $sql . ') AS count_subquery', $params);
return $result->current()->row_count;
Expand Down

0 comments on commit fe5ee56

Please sign in to comment.