Skip to content

fix in displayNamesInGroup - #9225

Merged
blizzz merged 4 commits into
owncloud:masterfrom
voxsim:fix_displayNamesInGroup
Sep 22, 2014
Merged

blizzz merged 4 commits into
owncloud:masterfrom
voxsim:fix_displayNamesInGroup

Conversation

@voxsim

@voxsim voxsim commented Jun 26, 2014

Copy link
Copy Markdown

When in displayNamesInGroup is specified a limit N, we did complex search only in the first N users.

For example:

  • user_backend with users (A, B, C, D, E) with the same GROUP
  • we call displayNamesInGroup($gid=GROUP, $search='E', $limit=4, $offset=0), where:
    • $group->searchUsers('', $limit, $offset); retrieves (A, B, C, D) as result1
    • $filteredUsers = $this->userManager->search($search); retrieves (E) as result2
      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:

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
        $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);
            $testUsers = true;
        } else {
            $filteredUsers = array();
            $testUsers = false;
        }

        return $filteredUsers;
}

thanks,
Simon

@ghost

ghost commented Jun 26, 2014

Copy link
Copy Markdown

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/

@PVince81

Copy link
Copy Markdown
Contributor

@schiesbn @blizzz

@blizzz

blizzz commented Jun 30, 2014

Copy link
Copy Markdown
Contributor

Did you try it with 50000 users?

@voxsim

voxsim commented Jul 2, 2014

Copy link
Copy Markdown
Author

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.

@blizzz

blizzz commented Jul 8, 2014

Copy link
Copy Markdown
Contributor

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?

@voxsim

voxsim commented Jul 8, 2014

Copy link
Copy Markdown
Author

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?

@blizzz

blizzz commented Jul 8, 2014

Copy link
Copy Markdown
Contributor

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.

@voxsim

voxsim commented Aug 28, 2014

Copy link
Copy Markdown
Author

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.

@voxsim

voxsim commented Sep 9, 2014

Copy link
Copy Markdown
Author

is it possible to ask a new build?

Because the problems don't seem related to my pull request.

@LukasReschke

Copy link
Copy Markdown
Contributor

@owncloud-bot Retest this please.

@voxsim

voxsim commented Sep 10, 2014

Copy link
Copy Markdown
Author

hmm @LukasReschke the call doesn't seem to work :)

@LukasReschke

Copy link
Copy Markdown
Contributor

@owncloud-bot This is ok to test.

@LukasReschke

Copy link
Copy Markdown
Contributor

@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.

@blizzz

blizzz commented Sep 15, 2014

Copy link
Copy Markdown
Contributor

Now this is an interesting and promising approach.
You will get bonus points when you can modify fetching of $filteredUsers

$filteredUsers = $this->userManager->search($search);

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.

@voxsim

voxsim commented Sep 15, 2014

Copy link
Copy Markdown
Author

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.

@blizzz

blizzz commented Sep 15, 2014

Copy link
Copy Markdown
Contributor

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.

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.

exactly

@voxsim

voxsim commented Sep 15, 2014

Copy link
Copy Markdown
Author

@blizzz I think it's almost done. Please check and let me know.

@schiessle

Copy link
Copy Markdown
Contributor

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)

@blizzz

blizzz commented Sep 16, 2014

Copy link
Copy Markdown
Contributor

@owncloud-bot this is ok to test

@voxsim

voxsim commented Sep 16, 2014

Copy link
Copy Markdown
Author

@schiesbn this contribution is MIT licensed!

@blizzz

blizzz commented Sep 16, 2014

Copy link
Copy Markdown
Contributor

mh, something takes very long here … i'll investigate it.

@ghost

ghost commented Sep 16, 2014

Copy link
Copy Markdown

🚀 Test Passed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7375/

@blizzz blizzz added this to the 2014-sprint-04-current milestone Sep 16, 2014
@blizzz

blizzz commented Sep 17, 2014

Copy link
Copy Markdown
Contributor

I am still investigating it, somehow too many LDAP search operations are triggered. But also I have seen that the condition sizeof($filteredUsers) > 0 will cancel the search when filteredUser returns 0 findings, which actually is not unlikely to happen. But even after leaving this out I do not get full result sets, but only a part.

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.

@blizzz

blizzz commented Sep 17, 2014

Copy link
Copy Markdown
Contributor

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.

@blizzz

blizzz commented Sep 18, 2014

Copy link
Copy Markdown
Contributor

Yeah, meanwhile I found another performance killer in core/ajax/share.php

$groups = OC_Group::getGroups($_GET['search']);

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.

@blizzz

blizzz commented Sep 18, 2014

Copy link
Copy Markdown
Contributor

forget the last one, although it is not really good, it in fact has not a too terrible performance. was following a wrong track.

@blizzz

blizzz commented Sep 18, 2014

Copy link
Copy Markdown
Contributor

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:

  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;

@voxsim

voxsim commented Sep 18, 2014

Copy link
Copy Markdown
Author

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?

@blizzz

blizzz commented Sep 18, 2014

Copy link
Copy Markdown
Contributor

This is already covered with sizeof($filteredUsers) === $searchLimit

@voxsim

voxsim commented Sep 18, 2014

Copy link
Copy Markdown
Author

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;
@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@ghost

ghost commented Sep 18, 2014

Copy link
Copy Markdown

🚀 Test Passed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org/job/pull-request-analyser/7462/

@blizzz

blizzz commented Sep 19, 2014

Copy link
Copy Markdown
Contributor

Thank you @voxsim

Other reviewers/testers/opinions? @schiesbn @th3fallen

@th3fallen

Copy link
Copy Markdown
Contributor

👍 this should also resolve #10513

@voxsim

voxsim commented Sep 19, 2014

Copy link
Copy Markdown
Author

Yes and please backport it to stable6 too

@th3fallen

Copy link
Copy Markdown
Contributor

@karlitschek Backport approval?

@karlitschek

Copy link
Copy Markdown
Contributor

please backport. thanks for the fix

blizzz added a commit that referenced this pull request Sep 22, 2014
@blizzz
blizzz merged commit b8a1340 into owncloud:master Sep 22, 2014
blizzz pushed a commit that referenced this pull request Sep 22, 2014
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;
@blizzz

blizzz commented Sep 22, 2014

Copy link
Copy Markdown
Contributor

backport to stable7 3ebd0b8

blizzz pushed a commit that referenced this pull request Sep 22, 2014
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
@blizzz

blizzz commented Sep 22, 2014

Copy link
Copy Markdown
Contributor

For stable6 tests needs to be adjusted it seems. It did not have a closer look due to limited time. @voxsim could you have a look, please? #11217

blizzz added a commit that referenced this pull request Oct 20, 2014
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants