In method impress() of file components/com_banners/model/banners.php, the model iterates through the id of each banner shown on the page and updates the impression count of each banner in table #__banners by one. Currently, the code issues an UPDATE query once for each banner id in each iteration. It is possible to remember all the banner id’s and issue one update query to update all the banner id’s using a WHERE...IN clause. Note that the item id’s are unique and this means that the original code iterates through unique id’s to increase the impression count by 1 and no id’s impression count will be increased by more than one in each invocation of impress() method. Thus it should be safe to remember all the id's first and then increase the count by one for all of them.
This is the original code. The code is issuing a query UPDATE #_banners SET impmade=(impmade+1) WHERE id = current_iteration_id once in each iteration (line 231 - line 248):
It is possible to reduce the number of queries issued by remembering all the id's in a separate loop and issue one query to update them all (line 230 - line 252):
The benefit of doing so is reducing the number of round trips between joomla and the database. As a result, the performance of rendering a page with a banner can be improved, especially for a page that have multiple banners.
I created an example page with 6 banners and nothing else. Using the originial code, rednering this page requires 26 queries and 220ms query time:
After the fix it only requires 21 queries and 85ms query time:
You should be able to see more performance improvement if you have more banners on the site.
Joomla! Version Joomla! 3.6.2 Stable [ Noether ] 4-August-2016 23:41 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
I have tested to your code and it works. I also have other code to be added (in the same function).
Yes, please. That's the needed procedure for any change. PR => min. 2 successfull tests submitted via https://issues.joomla.org/tracker/joomla-cms
Thus testing is as easy as possible for testers using Joomla Patch Tester component of mbabker.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-08-22 10:36:02 |
Closed_By | ⇒ | jeckodevelopment |
@mengqigu
Could you create a pull reguest (PR), please? So, anybody can test your solution.
https://docs.joomla.org/Using_the_Github_UI_to_Make_Pull_Requests