While optimizing a migrated Joomla website today, we noticed that one of the queries was taking an exceptionally long time. It was this one:
SELECT a.id, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(':', a.id, a.alias) ELSE a.id END as slug, CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(':', cc.id, cc.alias) ELSE cc.id END as catslug FROM #__content AS a LEFT JOIN #__categories AS cc ON cc.id = a.catid WHERE a.catid = 17 AND a.state = 1 AND a.access = 1 AND (a.state = 1 OR a.state = -1) AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '2013-09-03 04:41:23') AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '2013-09-03 04:41:23') ORDER BY a.created DESC
In our scenario, the above query was returning 37,461 rows and was taking over a second to execute! A second to execute a query, while somehow acceptable on small Joomla websites (if it’s just for one or two queries), is a major issue on large ones with high traffic because of the build-up effect (when many similar queries are run on the server simultaneously).
Now, going back to our query, a quick glimpse indicated that it was used to generate links, but why was it run on every page and what was making it run?
So we searched for the file containing patterns from the above query, and we discovered that it was the file pagenavigation.php (a plugin) which is located under the /httpdocs/plugins/content/pagenavigation directory. This plugin is responsible for displaying navigation at the bottom of an article (Next Article, Previous Article, etc…) – this made perfect sense on why the query was run on every page. Unfortunately, our discovery also revealed, without a doubt, that it is Joomla’s core that is causing this problem.
Just to make sure before openly blaming Joomla, we opened up the above file and we were surprised to see that the query ran when “Show Navigation” (a setting at the article level) is enabled (and this setting is enabled by default). We were disappointed with the inefficiency of this plugin. Why-oh-why does it need to get the slugs of all the articles in the same category when it only needs a few? In our case, the query was returning close to 40k results, and was dramatically slowing down the whole website. To add insult to injury, we weren’t even using navigation on the website – it was just enabled, but not being used. So we disabled it globally. This was done the following way:
- We logged in to the backend of the Joomla website.
-
We clicked on Content -> Article Manager.
-
We clicked on the Options button at the top right.
-
We clicked on the Articles tab (usually the Articles tab is selected by default because it’s the first one).
-
We clicked on Hide next to Show Navigation, and then we clicked on Save at the top right.
-
That was it! The site ran super fast and our client was very satisfied.
As the title of the article implies, page navigation is a problem on large Joomla websites (10,000+ articles) – it’s not that much of a problem on smaller websites.
Now, what if a large Joomla website really needs page navigation? Well, there are two options:
- Contact some Joomla experts (such as us) and ask them to modify the default page navigation plugin.
-
Ask some Joomla experts (again, that would be us!) to develop another page navigation plugin and use it instead of the default one.
The first option above is the fastest, but, on the flip side, it requires modifying Joomla’s core which means that future updates to your Joomla website may overwrite the modifications done on that particular plugin.
The second option doesn’t require any core modification, but it’s much more complicated and requires more work, especially because all the views in Joomla use the default page navigation instead.
In any case, and whatever your option is, we are here to help. Just contact us and let us prove to you how experienced, fast, and professional we are. Oh, and don’t you worry about our fees – they are very, very affordable!