]> source.dussan.org Git - nextcloud-server.git/commitdiff
contactsmanager shall limit number of results early 22057/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Thu, 30 Jul 2020 10:50:04 +0000 (12:50 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 31 Jul 2020 10:42:17 +0000 (12:42 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
lib/private/Contacts/ContactsMenu/ContactsStore.php
lib/private/Contacts/ContactsMenu/Manager.php
lib/public/Contacts/ContactsMenu/IContactsStore.php

index b0bd99b844ec3f0567efcb59c84c803f75f7b128..81c4f5d6baf3a502fee5ffdf87ffd70aa9457a21 100644 (file)
@@ -73,11 +73,23 @@ class ContactsStore implements IContactsStore {
         * @param string|null $filter
         * @return IEntry[]
         */
-       public function getContacts(IUser $user, $filter) {
-               $allContacts = $this->contactsManager->search($filter ?: '', [
-                       'FN',
-                       'EMAIL'
-               ]);
+       public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
+               $options = [];
+               if ($limit !== null) {
+                       $options['limit'] = $limit;
+               }
+               if ($offset !== null) {
+                       $options['offset'] = $offset;
+               }
+
+               $allContacts = $this->contactsManager->search(
+                       $filter ?: '',
+                       [
+                               'FN',
+                               'EMAIL'
+                       ],
+                       $options
+               );
 
                $entries = array_map(function (array $contact) {
                        return $this->contactArrayToEntry($contact);
@@ -122,7 +134,7 @@ class ContactsStore implements IContactsStore {
                if ($excludedGroups) {
                        $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
                        $decodedExcludeGroups = json_decode($excludedGroups, true);
-                       $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups :  [];
+                       $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : [];
 
                        if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
                                // a group of the current user is excluded -> filter all local users
index 293f1366b053835738c2d432582734cbd05de203..c3d4e74e433b3a194fafb2ba17bc12f3180f6e4a 100644 (file)
@@ -66,7 +66,7 @@ class Manager {
                $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
                $topEntries = [];
                if (strlen($filter) >= $minSearchStringLength) {
-                       $entries = $this->store->getContacts($user, $filter);
+                       $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults);
 
                        $sortedEntries = $this->sortEntries($entries);
                        $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults);
index c64b95fb85d40eb5b4f35ccc9222476c177a9cea..fceb507f0cf11f6154777790cf9a16590aa0d069 100644 (file)
@@ -33,11 +33,13 @@ interface IContactsStore {
 
        /**
         * @param IUser $user
-        * @param $filter
+        * @param string $filter
+        * @param int $limit added 19.0.2
+        * @param int $offset added 19.0.2
         * @return IEntry[]
         * @since 13.0.0
         */
-       public function getContacts(IUser $user, $filter);
+       public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null);
 
        /**
         * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith)