This repository has been archived by the owner. It is now read-only.

Fix performance issues in JModelLegacy::_getListCount() #1532

Merged
merged 3 commits into from Sep 16, 2012

Conversation

Projects
None yet
2 participants
@mahagr
Contributor

mahagr commented Sep 15, 2012

Current code in JModelLegacy::_getListCount() forces database engine to fetch all items instead of just counting them. With hundreds of thousands or millions of rows the query gets very inefficient even if no results are actually fetched by the function.

Cloning and modifying JDatabaseQuery object into COUNT(*) allows database engine to do optimizations that will considerably speed up the code even with very simple queries like:

SELECT * FROM jos_users

if there are hundreds of thousands of users.

libraries/legacy/model/legacy.php
+ $query = clone $query;
+ $query->clear('select')->clear('order')->select('COUNT(*)');
+ $this->_db->setQuery($query);
+

This comment has been minimized.

Show comment Hide comment
@pasamio

pasamio Sep 15, 2012

Contributor

Can you remove the white space on this line?

@pasamio

pasamio Sep 15, 2012

Contributor

Can you remove the white space on this line?

@mahagr

This comment has been minimized.

Show comment Hide comment
@mahagr

mahagr Sep 16, 2012

Contributor

Sorry, project settings were wrong. Now it should be better.

Contributor

mahagr commented Sep 16, 2012

Sorry, project settings were wrong. Now it should be better.

pasamio added a commit that referenced this pull request Sep 16, 2012

Merge pull request #1532 from mahagr/getlistcount
Fix performance issues in JModelLegacy::_getListCount()

@pasamio pasamio merged commit bb21e3a into joomla:staging Sep 16, 2012

@pasamio

This comment has been minimized.

Show comment Hide comment
@pasamio

pasamio Sep 16, 2012

Contributor

Sweet! Nice addition!

Contributor

pasamio commented Sep 16, 2012

Sweet! Nice addition!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.