diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2020-08-03 17:54:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-03 17:54:40 +0200 |
commit | 7a1bd4e8a2e883171aea7ffc53a22ba6084638ec (patch) | |
tree | 218eb57e6551f585d3e848350561600655757d9a | |
parent | 9d56c5142b6d2ea63607cd1c63701f1698e977df (diff) | |
parent | dc98aaa2246c0b084151f8b62af144ab419fcd0e (diff) | |
download | nextcloud-server-7a1bd4e8a2e883171aea7ffc53a22ba6084638ec.tar.gz nextcloud-server-7a1bd4e8a2e883171aea7ffc53a22ba6084638ec.zip |
Merge pull request #22091 from nextcloud/backport/22057/stable19
[stable19] contactsmanager shall limit number of results early
-rw-r--r-- | lib/private/Contacts/ContactsMenu/ContactsStore.php | 24 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/Manager.php | 2 | ||||
-rw-r--r-- | lib/public/Contacts/ContactsMenu/IContactsStore.php | 6 |
3 files changed, 23 insertions, 9 deletions
diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index b0bd99b844e..81c4f5d6baf 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -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 diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php index 293f1366b05..c3d4e74e433 100644 --- a/lib/private/Contacts/ContactsMenu/Manager.php +++ b/lib/private/Contacts/ContactsMenu/Manager.php @@ -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); diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php index c64b95fb85d..fceb507f0cf 100644 --- a/lib/public/Contacts/ContactsMenu/IContactsStore.php +++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php @@ -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) |