-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance issues in sites with a lot of users groups #11853
Conversation
* | ||
* @return array | ||
* | ||
* @since DEPLOY_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phproberto it is __DEPLOY_VERSION__
;) I have send you a PR to fix that phproberto#4. Thanks.
Result.
note: I have not exiplite tested the performance. |
I have tested this item ✅ successfully on a4d42a4 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11853. |
__DEPLOY_VERSION__ for the new code
Merged. Thanks @zero-24 :) |
I have tested this item ✅ successfully on 3f1c170 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11853. |
I have tested this item ✅ successfully on This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11853. |
I have broken travis :( If that is fixed we can set it RTC. phproberto#5 Thanks 👍 |
Sorry i have implemented to much here.
👍 Merged @zero-24 |
I have tested this item ✅ successfully on 2d15209 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11853. |
Since the last change was only a CS I will move this to RTC Thank you @phproberto |
I have tested this item ✅ successfully on 2d15209 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11853. |
Description
#__usergroups
table should really extendJTableNested
but it's there untouched for years. The main issue is thatlevel
of groups is not stored in database when a group is saved and that forces that any operation that requires to retrieve a list of groups with their levels uses a query like:That uses MySQL to calculate the groups level but it's a really expensive query (~0.5 seconds for 1500 groups). Most Joomla sites have < 10 user groups so the performance issues are not noticeable but as you will see in the benchmarks below this speeds things a lot.
In the near future we should modify database table to add columns, etc. but I don't have the time now to deal with such a big change and the issues it may cause.
This PR replaces the method to retrieve groups levels & paths. It really improves data reliability because it uses the group tree to populate that data which is correct even when something went wrong and lft & rgt values are wrong.
Summary of Changes
The new method to populate groups levels & paths is quite simple: the list of groups is retrieved with a simple query (~0.011 seconds for 1500 groups) like:
then a recursive php function traverses the group tree until it reaches
parent_id
= 0 which is assigned to level 0. Additionally when it reaches that level it starts to populate the group path. Data is sent back to the recursive function so all the children groups get the correct path & level.This PR gives us other benefits:
JHelperUsergroups::getInstance()
) that can be used to deal with user groups. Using a singleton ensures that no matter how many times you need to get the available user groups in the same page load (it happens a lot in com_users backend managements) it will only retrieve the list once.JHelperUsergroups
becomes the central place to deal with existing groups.Benchmarks
I did a benchmark for each function I have modified. Each benchmark value shown here is an average of 50 measurements done on a Joomla site with 1500 user groups. All the queries benchmarked use
SQL_NO_CACHE
to ensure that no cache affects data.Benchmark system information:
Performance improvements for 1500 user groups:
Testing Instructions
Perform any additional test you think may be applicable.
If you want to test performance and you need to create groups I have created a small shit snippet:
You can place that in backend isis template index.php and it will allow you to create groups with urls like:
Remember to remove that shit when you are finished testing this and don't be stupid to use it in other places because is not secure :P
Documentation Changes Required
Example usage of
JHelperUsergroup
as singleton:Example usage of
JHelperUsergroup
as standard instance: