Skip to content

Commit

Permalink
Fix performance issues in JModelLegacy::_getListCount()
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Sep 15, 2012
1 parent 1d62cf3 commit da608f1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions libraries/legacy/model/legacy.php
Expand Up @@ -313,10 +313,25 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
*/ */
protected function _getListCount($query) protected function _getListCount($query)
{ {
$this->_db->setQuery($query); if ($query instanceof JDatabaseQuery)
$this->_db->execute(); {
// Create COUNT(*) query to allow database engine to optimize the query.
$query = clone $query;
$query->clear('select')->clear('order')->select('COUNT(*)');
$this->_db->setQuery($query);

return (int) $this->_db->loadResult();
}
else
{
// Performance of this query is very bad as it forces database engine to go
// through all items in the database. If you don't use JDatabaseQuery object,
// you should override this function in your model.
$this->_db->setQuery($query);
$this->_db->execute();


return $this->_db->getNumRows(); return $this->_db->getNumRows();
}
} }


/** /**
Expand Down

0 comments on commit da608f1

Please sign in to comment.