I have like 16000 entries in my categories table. While adding or editing a category from backend, it takes a lot of time and the time from debug is 261642.9 ms which is around 4 minutes to load the page.
Faster loading time
It takes a lot of time and the time for querying is 261642.9 ms which is around 4 minutes to load the page.
Debugging the system, most of the query time is spent in the following query.
SELECT DISTINCT a.id AS value, a.title AS text, a.level, a.published, a.lft
FROM (
SELECT id,title,level,published,parent_id,extension,lft,rgt
FROM jos_categories
WHERE (extension = 'com_content' OR parent_id = 0)
AND published IN (0,1)) AS a
LEFT JOIN `jos_categories` AS b
ON a.lft > b.lft
AND a.rgt < b.rgt
ORDER BY a.lft ASC
This is the form field 'categoryedit'
administrator/components/com_categories/models/fields/categoryedit.php
Looking at the PHP code the query has a sub-query (used in FROM of main query) and a left join with the table itself
$query->from('(' . $subQuery->__toString() . ') AS a')
->join('LEFT', $db->quoteName('#__categories') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
can become:
$query->from('(' . $subQuery->__toString() . ') AS a')
;//->join('LEFT', $db->quoteName('#__categories') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
This is amazing. But I don't understand the purpose of the join but it is working.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-01-12 09:32:58 |
Closed_By | ⇒ | akfaisel |
Why did you close this ? it is a real issue and it still needs to be fixed, i will make a PR when i get some more time so that more people can test and hopefully it will be accepted too
the left join is for getting child categories, not sure if you can remove it entirely. Wondering how many articles the site has?
The time for querying has come down from 261642.9 ms to 200 ms and the page loads so fast.
I'm sorry for closing the issue; I shall reopen it.
The issue is not with number of articles but with CATEGORIES. You can also try with the SQL dump I've provided. After installing the dump, just go to Add or Edit Category and it will take at least 4 mins for loading the page.
Status | Closed | ⇒ | New |
Closed_Date | 2016-01-12 09:32:57 | ⇒ | |
Closed_By | akfaisel | ⇒ |
the left join is for getting child categories, not sure if you can remove it entirely. Wondering how many articles the site has?
well you are talking about the join that produces the 'p' table alias and it is that is a different Join:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_categories/models/fields/categoryedit.php#L199-L205
// If parent isn't explicitly stated but we are in com_categories assume we want parents
if ($oldCat != 0 && ($this->element['parent'] == true || $jinput->get('option') == 'com_categories'))
{
// Prevent parenting to children of this item.
// To rearrange parents and children move the children up, not the parents down.
$query->join('LEFT', $db->quoteName('#__categories') . ' AS p ON p.id = ' . (int) $oldCat)
->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
...
}
and it is activated in this case of "edit category" and not in the case of "add new category"
i speak of the join that produces the 'b' table alias , in this case it does nothing, because
@akfaisel the original query that you posted looks like its from "add new category"
if you you also test with "edit category"
nested set model that is used to calculate rgt/lft in core joomla is exponentially slower on inserts or any changes to the tree structure compared to the adjacent model using parent_ids. i've seen sites (on j3) completely crashed upon wrong rgt/lft values at these tables due to various mysql events such as concurret inserts without locks/transactions or caused by bugs in previous joomla versions JTableNested being used too fast (inside foreach)
i already suggested to get rid of the "nested set model" but it would mean lot's of code to get reversed to the old-stable joomla 1.5
mysql itself compared to commercial solutions and my knowledge does not natively support the nested set model.
Status | New | ⇒ | Confirmed |
@franz-wohlkoenig
Some reading my comments could make a PR, unfortunately , currently, i don't have time to do it
Hi @akfaisel is this is still relevant?
@ggppdk @franz-wohlkoenig
Status | Confirmed | ⇒ | Information Required |
set Status on "Information Required".
If this PR get no Response, it will be closed at 23th July 2017.
@franz-wohlkoenig @rdeutz
i have made a PR ...
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-06-22 20:57:37 |
Closed_By | ⇒ | zero-24 |
Here is the dump of the categories table - http://www.filedropper.com/joscategories
Please replace the file content with your table prefix. I have used jos
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8884.