Repository navigation
fix in displayNamesInGroup - #9225
Conversation
…arch only in the first N users
|
Thanks a lot for your contribution! Contributions to the core repo require a signed contributors agreement http://owncloud.org/contribute/agreement/ Alternatively you can add a comment here stating that this contribution is MIT licensed. Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/ |
|
@schiesbn @blizzz |
|
Did you try it with 50000 users? |
|
Nope, I noticed that there aret't any test cases about this function with limit and offset specified. I would to add a test case, but I don't really understand how to use the test suite. I have an enterprise edition and I tried to copy the testdir from github in my owncloud's root dir, after I runned ./autotest.sh but it doesn't work. |
|
Well, it will take incredibly long in that case. However we do not do test performance here. Doc on unit tests goes here: http://doc.owncloud.org/server/7.0/developer_manual/core/unit-testing.html does it help? |
|
Hmm, Yes, it helps and yes you are right it will take incredibly long in that case, but at least we have a right result :) Btw, why don't use this implementation? public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid);
if(is_null($group)) {
return array();
}
// only user backends have the capability to do a complex search for users
$groupUsers = $group->searchUsers($search, $limit, $offset);
$search = trim($search);
if(!empty($search)) {
//TODO: for OC 7 earliest: user backend should get a method to check selected users against a pattern
$filteredUsers = $this->userManager->search($search, $limit, $offset);
$testUsers = true;
} else {
$filteredUsers = array();
$testUsers = false;
}
$matchingUsers = array();
foreach($groupUsers as $user) {
if(!$testUsers || isset($filteredUsers[$user->getUID()])) {
$matchingUsers[$user->getUID()] = $user->getDisplayName();
}
}
return $matchingUsers;
}Instead of calling searchUsers with empty string, we call specifying $search, is there any way to search with an empty string instead to use $search parameter? |
|
Because only the user backend can do a an advanced search which does not only cover user id and display name, but pass anything to the backend server. LDAP makes use of this for instance. The group backend is limited to user id and display name. |
|
Sorry @blizzz I forgot to answer :) Ok I understand the difference between group and user backend, so in the first search we pass an empty string to permit ldap user backend to do its complex searches and in the end of function we verify the users with the users of the group. I change in some way the logic, check my last commit where I add some tests too. |
|
is it possible to ask a new build? Because the problems don't seem related to my pull request. |
|
@owncloud-bot Retest this please. |
|
hmm @LukasReschke the call doesn't seem to work :) |
|
@owncloud-bot This is ok to test. |
|
@DeepDiver1975 This needs build approval. But it seems that @owncloud-bot does not consider me as his master. Can you take a look at that? THX. |
|
Now this is an interesting and promising approach. to also use a limit and offset to make it faster with big user bases. Load a batch of users, if the result will still be < limit take the next batch until the limit is fulfilled or no more users are retrieved. |
|
Ok, I can use a default and hard coded limit (like 15) or do you prefer to use the the $limit passed to the function? Btw I have to load a batch of users, if the result will still be < limit+offset take the next batch until the limit+offset is fulfilled or no more users are retrieved. After the first process slice taking the last N users where N is equal to limit. |
|
Let's go with $limit * 2. Having in mind that the result will probably be smaller, so we can ask for a bit more. Hopefully this can save a or two search operation.
exactly |
|
@blizzz I think it's almost done. Please check and let me know. |
|
tested, works fine. Code looks also good to me @blizzz what do you think? Would be great to fix it for the next release, see also issue #10513 @voxsim did you already signed the contributer agreement like mentioned here: #9225 (comment) |
|
@owncloud-bot this is ok to test |
|
@schiesbn this contribution is MIT licensed! |
|
mh, something takes very long here … i'll investigate it. |
|
🚀 Test Passed. 🚀 |
|
I am still investigating it, somehow too many LDAP search operations are triggered. But also I have seen that the condition Another issue is that if a group contains less then 15 users that match the criteria we will still cycle through all users available in the user management. That's no good. We should only cycle through the users available in the group. I don't see that we come around introducing a method for user backends that get a set of users and the search pattern as input and returns only those users that match the criteria. In order to keep up compatibility it needs to be optional, which makes it trickier. |
|
I have a working prototype. I introduced an interface for user backends that defined a method called match() which is also introduced to the user manager. A set of users and a search pattern is passed. The user manager will iterate through all user backends. If the next user backend implements the interface, it's match() method is called. Others a skipped for now. If there are unconfirmed users left after all the matches were run and skipped backends are registered, a getUsers is performed on this backends. Because we will introduce this method to local users (yet to do) and to LDAP users (working prototype) the most important backends are done. I believe those in user_external cannot search anyway, but i need to reassure this. Any other possible backend will still work and has the possibility to implement it as well. Thoughts? Code and refinements tomorrow. |
|
Yeah, meanwhile I found another performance killer in core/ajax/share.php takes awefully lot, especially because we only need the user's groups, alas filtered. getUserGroups does not take a search filter unfortunately. For the other case (sharing not limited to own groups), it is enough to provide a limit as done with users. I will open this as a seperate issue however. |
|
forget the last one, although it is not really good, it in fact has not a too terrible performance. was following a wrong track. |
|
hahahaha, i was uncomfortable with this, so i went back to start (which is @voxsim solution) and tried to find out why it was not working for me. Mainly it was because of #10526. The performance with a lot of users for LDAP is still bad, but we can keep it out. Now I need to finish #10527 and get it included, or we do it subsequently and first get this stuff done and merged, both possible. Maybe latter is easier. @voxsim can I ask you for final changes:
|
|
hmmm, I disagree with the first point (remove sizeof($filteredUsers) > 0 as condition) because we should stop if we don't get any users from a search operation, am I wrong? |
|
This is already covered with sizeof($filteredUsers) === $searchLimit |
|
you are right! done ;) |
2. use count instead of sizeof. Latter is an alias to first one, practically we stick to count everywhere. Having it consistent helps with readability. 3. move whitespace so we have $groupUsers[] = $filteredUser; instead of $groupUsers []= $filteredUser;
|
A new inspection was created. |
|
🚀 Test Passed. 🚀 |
|
Thank you @voxsim Other reviewers/testers/opinions? @schiesbn @th3fallen |
|
👍 this should also resolve #10513 |
|
Yes and please backport it to stable6 too |
|
@karlitschek Backport approval? |
|
please backport. thanks for the fix |
fix in displayNamesInGroup: when specified limit N, we did complex search only in the first N users change logic in displayNamesInGroup and add some unit tests add more logic in displayNamesInGroup for big user bases 1. remove sizeof($filteredUsers) > 0 as condition 2. use count instead of sizeof. Latter is an alias to first one, practically we stick to count everywhere. Having it consistent helps with readability. 3. move whitespace so we have $groupUsers[] = $filteredUser; instead of $groupUsers []= $filteredUser;
|
backport to stable7 3ebd0b8 |
fix in displayNamesInGroup: when specified limit N, we did complex search only in the first N users change logic in displayNamesInGroup and add some unit tests add more logic in displayNamesInGroup for big user bases 1. remove sizeof($filteredUsers) > 0 as condition 2. use count instead of sizeof. Latter is an alias to first one, practically we stick to count everywhere. Having it consistent helps with readability. 3. move whitespace so we have $groupUsers[] = $filteredUser; instead of $groupUsers []= $filteredUser; Conflicts: tests/lib/group/manager.php
When in displayNamesInGroup is specified a limit N, we did complex search only in the first N users.
For example:
In conclusion, $matchingUsers is empty because we loop in result1 and we search if one element in result1 is present in result2, but in this example we don't have any of it.
We found it because this function is called from core/ajax/share.php when a USER A try to share something with USER B and displayNamesInGroup is called with limit 15, but in our backend we have like 32 users.
Finally, we don't understand why the function is so complicated, because, for me, it should be done in this way:
thanks,
Simon