Merge pull request #22091 from nextcloud/backport/22057/stable19

[stable19] contactsmanager shall limit number of results early
This commit is contained in:
blizzz 2020-08-03 17:54:40 +02:00 committed by GitHub
commit 7a1bd4e8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -73,11 +73,23 @@ class ContactsStore implements IContactsStore {
* @param string|null $filter * @param string|null $filter
* @return IEntry[] * @return IEntry[]
*/ */
public function getContacts(IUser $user, $filter) { public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
$allContacts = $this->contactsManager->search($filter ?: '', [ $options = [];
if ($limit !== null) {
$options['limit'] = $limit;
}
if ($offset !== null) {
$options['offset'] = $offset;
}
$allContacts = $this->contactsManager->search(
$filter ?: '',
[
'FN', 'FN',
'EMAIL' 'EMAIL'
]); ],
$options
);
$entries = array_map(function (array $contact) { $entries = array_map(function (array $contact) {
return $this->contactArrayToEntry($contact); return $this->contactArrayToEntry($contact);

View File

@ -66,7 +66,7 @@ class Manager {
$minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
$topEntries = []; $topEntries = [];
if (strlen($filter) >= $minSearchStringLength) { if (strlen($filter) >= $minSearchStringLength) {
$entries = $this->store->getContacts($user, $filter); $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults);
$sortedEntries = $this->sortEntries($entries); $sortedEntries = $this->sortEntries($entries);
$topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults);

View File

@ -33,11 +33,13 @@ interface IContactsStore {
/** /**
* @param IUser $user * @param IUser $user
* @param $filter * @param string $filter
* @param int $limit added 19.0.2
* @param int $offset added 19.0.2
* @return IEntry[] * @return IEntry[]
* @since 13.0.0 * @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) * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith)