Creating a New Article in Joomla Taking a Long Time? Read This!

We had a client today complaining that when he clicks on the New button in Joomla’s Article Manager page, he has to wait for a long time for the Add New Article page to appear (the problem also happens when he clicks on an existing article in the Article Manager page to edit it). We did a quick analysis which revealed that the page was taking about 8 seconds to load, which is not normal since this page should take less than a half a second to load under normal circumstances.

Naturally, the first thing that we did was checking the slow queries in the MySQL Slow Query Log, but, alas, no slow query was logged there. This meant that the cause of the slowdown might be a hack, a rogue extension, or a batch of very similar queries being executed at the same time (typically in a while loop). We felt that this wasn’t going to be an easy task!

Luckily, we were wrong, since the first thing that we did was checking the HTML code generated on the New Article page (in order to see whether there was a malicious JavaScript there), and while doing that, we noticed one thing, there were 7,000+ tags being loaded into that new page! Naturally, we suspected that it was the huge number of tags causing the slowness, and so we completely removed the Tags field from the page the following way:

  • We opened the file article.xml located under the administrator/components/com_content/models folder.
  • We removed the following code:

    <field name="tags"
    	type="tag"
    	label="JTAG"
    	description="JTAG_DESC"
    	class="span12"
    	multiple="true"
    >
    </field>

  • We saved the file and uploaded it back.

  • We tested the Add New Article page, and, surprise surprise (well, not really a surprise, let alone two surprises), the page loaded in less than a second as it should be! (Removing the above XML content ensured that the Tags input box will no longer be loaded.)

Aha! So the reason was the huge number of tags! But of course, we can’t tell our client, who heavily relies on tags on his Joomla website not to use them, so we had to find an alternative solution to optimize the loading of this page, and so we did, and here it is:

  • We opened the file tag.php located under the libraries/cms/form/field folder.
  • We changed the following code:

    $query = $db->getQuery(true)
    	->select('DISTINCT a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft')
    	->from('#__tags AS a')
    	->join('LEFT', $db->qn('#__tags') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');

    to:

    $query = $db->getQuery(true)
    	->select('DISTINCT a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft')
    	->from('#__tags AS a');

  • We removed the following lines:

    // Prepare nested data
    if ($this->isNested())
    {
    	$this->prepareOptionsNested($options);
    }
    else
    {
    	$options = JHelperTags::convertPathsToNames($options);
    }

  • We then saved the file and uploaded it back.

  • We reverted the changes we did on the aforementioned article.xml and we monitored the loading page and it still loaded in under a second! The problem was solved and we were able to keep the Tags field!

We probably have mentioned this before, we don’t like tags (in fact, we did, we did mention this before)! And that’s just another reason why we don’t like them and whey they should be avoided, yet people still use them and some extensions also use them (in a subtle way – in fact, the tags on our client’s website were generated by HWD MediaShare, which is a 3rd party media extension). But, if you’re stuck with them and it’s taking your website a long time to load the Add New Article page, then try the above solution and hopefully it should work for you. If it doesn’t, or if the solution presented here sounds a bit intimidating, then please contact us. We will solve your problem quickly, professionally, and for a very affordable fee!

No comments yet.

Leave a comment