?
avatar mengqigu
mengqigu
20 Aug 2016

Description

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):

screen shot 2016-08-20 at 17 46 11

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):
screen shot 2016-08-20 at 17 49 49

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:
screen shot 2016-08-20 at 18 00 46

After the fix it only requires 21 queries and 85ms query time:
screen shot 2016-08-20 at 18 01 31

You should be able to see more performance improvement if you have more banners on the site.

System information

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

Votes

# of Users Experiencing Issue
0/1
Average Importance Score
1.00

avatar mengqigu mengqigu - open - 20 Aug 2016
avatar bertmert
bertmert - comment - 21 Aug 2016

@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

avatar daflanck
daflanck - comment - 21 Aug 2016

I have tested to your code and it works. I also have other code to be added (in the same function).

avatar mengqigu
mengqigu - comment - 21 Aug 2016

@daflanck Thanks!

@bertmert Sorry it was my first time reporting issues in Joomla and I forgot about the pull request. Since daflanck has tested my code, do you need the pull request any more? Thanks!

avatar bertmert
bertmert - comment - 22 Aug 2016

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.

22-08-_2016_09-09-55

avatar alikon
alikon - comment - 22 Aug 2016

please test #11716

avatar jeckodevelopment
jeckodevelopment - comment - 22 Aug 2016

Closing since we have a PR to test.
Please test #11716

avatar jeckodevelopment jeckodevelopment - change - 22 Aug 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-08-22 10:36:02
Closed_By jeckodevelopment
avatar jeckodevelopment jeckodevelopment - close - 22 Aug 2016
avatar mengqigu
mengqigu - comment - 22 Aug 2016

@bertmert Thanks! Sorry I didn't have time yesterday night to work on the patch.

@alikon Thanks for the PR!

Add a Comment

Login with GitHub to post a comment