core icon indicating copy to clipboard operation
core copied to clipboard

Share: Number of results limited before the search pattern has been applied

Open nosignleft opened this issue 12 years ago • 7 comments

Expected behavior

When trying to share a file or folder in "groups_only" mode, we should be able to find users beyond the first 15 contacts.

Actual behavior

At least since 6.0.2, the result limit is applied before the search pattern.

Steps to reproduce

  1. Select groups_only mode in administration
  2. Create more than 15 users "a.user", "b.user", etc. and linked to a common group "1234"
  3. Login with one of the account, and try to share a file to "r.user" or "y.user" for instance
  4. The user is not found

Fix

It seems that the code in lib/private/group/manager.php apply the limit of results before the search pattern

--- /var/www/html/sites/pp_otdrive_com/www/lib/private/group/manager.php    2014-04-29 14:25:06.093301644 +0200
+++ lib/private/group/manager.php   2014-06-05 12:28:25.107689319 +0200
@@ -175,7 +175,10 @@
            return array();
        }
        // only user backends have the capability to do a complex search for users
-       $groupUsers  = $group->searchUsers('', $limit, $offset);
+       // $limit == -1: the limit should not be applied now on an unfiltered result!
+       $groupUsers  = $group->searchUsers('', -1, $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

nosignleft avatar Jun 05 '14 12:06 nosignleft

@schiesbn

karlitschek avatar Jun 05 '14 12:06 karlitschek

@blizzz

PVince81 avatar Aug 19 '14 09:08 PVince81

:-1: wlll takes ages with many (really many) users

blizzz avatar Aug 21 '14 10:08 blizzz

@craigpg @blizzz How do we move forward here?

karlitschek avatar Dec 05 '14 21:12 karlitschek

@blizzz @craigpg wasn't this fix recently ?

@nosignleft have you tried with 7.0.5 or 8.0.2 ?

PVince81 avatar Mar 26 '15 22:03 PVince81

@PVince81 didn't had the time to try the latest versions, because I have to reapply some custom modifications. But from what I see, reading the source code of the 8.0.2, it might be fixed with the search done chunk by chunk to limit the performance impact.

                if(!empty($search)) {
                        // only user backends have the capability to do a complex search for users
                        $searchOffset = 0;
                        $searchLimit = $limit * 100;
                        if($limit === -1) {
                                $searchLimit = 500;
                        }

                        do {
                                $filteredUsers = $this->userManager->search($search, $searchLimit, $searchOffset);
                                foreach($filteredUsers as $filteredUser) {
                                        if($group->inGroup($filteredUser)) {
                                                $groupUsers[]= $filteredUser;
                                        }
                                }
                                $searchOffset += $searchLimit;
                        } while(count($groupUsers) < $searchLimit+$offset && count($filteredUsers) >= $searchLimit);

                        if($limit === -1) {
                                $groupUsers = array_slice($groupUsers, $offset);
                        } else {
                                $groupUsers = array_slice($groupUsers, $offset, $limit);
                        }
                } else {
                        $groupUsers = $group->searchUsers('', $limit, $offset);
                }

nosignleft avatar Mar 29 '15 13:03 nosignleft

I am pretty sure this was fixed some time ago, but don't have a PR at hand. Please reopen, if you come across it again.

blizzz avatar Mar 30 '15 08:03 blizzz