Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable19] contactsmanager shall limit number of results early #22091

Merged
merged 1 commit into from Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Expand Up @@ -73,11 +73,23 @@ public function __construct(IManager $contactsManager,
* @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);
Expand Down Expand Up @@ -122,7 +134,7 @@ private function filterContacts(IUser $self,
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
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Contacts/ContactsMenu/Manager.php
Expand Up @@ -66,7 +66,7 @@ public function getEntries(IUser $user, $filter) {
$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);
Expand Down
6 changes: 4 additions & 2 deletions lib/public/Contacts/ContactsMenu/IContactsStore.php
Expand Up @@ -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)
Expand Down