-
Notifications
You must be signed in to change notification settings - Fork 825
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
FIX 11577 performance issues with large list of groups #11578
base: 5
Are you sure you want to change the base?
Conversation
120baae
to
c8b41b0
Compare
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.
Thanks for submitting this - I've requested a few changes below.
FYI the beta release for CMS 5.4 (which is also the feature freeze for all of CMS 5) is currently scheduled for Feb 17, so for this change to be included in CMS 5 it will need to be merged before then.
I will do my best to be quick to respond and review this PR as you update it.
src/Security/Group.php
Outdated
private static $searchable_fields = [ | ||
'Title', | ||
'Description', | ||
]; |
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.
I don't think this change should alter the searchable fields
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.
Without the default search context is empty and the SearchableDropdownField does not filter.
src/Security/Group.php
Outdated
$threshold = DBForeignKey::config()->get('dropdown_field_threshold'); | ||
$overThreshold = $groups->count() > $threshold; |
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.
We shouldn't be using that unrelated configuration here.
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.
This are the default settings for SearchableDropdownField. I can create a extra config for that.
public function getBreadcrumbTitle(): string | ||
{ | ||
return $this->getBreadcrumbs(' > '); | ||
} |
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.
Why do we need this new method?
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.
This is the Label for the FormField.
private function dedupeCode(): void | ||
{ | ||
$currentGroups = Group::get() | ||
->exclude('ID', $this->ID) | ||
->map('Code', 'Title') | ||
->toArray(); | ||
$code = $this->Code; | ||
$count = 2; | ||
while (isset($currentGroups[$code])) { | ||
$code = $this->Code . '-' . $count; | ||
$count++; | ||
|
||
if ($code) { | ||
while ($this->checkIfCodeExists($code)) { | ||
$code = $this->Code . '-' . $count; | ||
$count++; | ||
} | ||
|
||
$this->setField('Code', $code); | ||
} | ||
$this->setField('Code', $code); | ||
} | ||
|
||
private function checkIfCodeExists(string $code): bool | ||
{ | ||
return Group::get()->filter('Code', $code)->exclude('ID', $this->ID)->exists(); | ||
} |
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.
How do changes to the deduping code relate to usage of a different form field?
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.
This is more or less the same issue as with the large list in the FormField. Without you are not able to save a group if you have many of them.
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.
You can check the output of my generater script above with and without the change. Without the script will get slower with each iteration.
src/Security/Member.php
Outdated
$threshold = DBForeignKey::config()->get('dropdown_field_threshold'); | ||
$overThreshold = $groups->count() > $threshold; |
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.
Like with the change in Group
, we shouldn't use this unrelated configuration.
7ffbd21
to
99aaf6b
Compare
99aaf6b
to
9ec4dd6
Compare
I created custom configs, a getter for a custom search context and added some comments. |
Description
If you have many groups you can no longer edit a member in the admin.
Manual testing steps
As this is a performance issue, I am not sure howto create a unittest for this. But here is a task to create a massive amount of groups:
Issues
Pull request checklist