Skip to content

Commit 038045d

Browse files
authored
Merge pull request #18816 from nextcloud/bugfix/noid/paginate-contacts-search
Use paginated search for contacts
2 parents 24e5894 + 6709833 commit 038045d

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

apps/dav/lib/CardDAV/AddressBookImpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public function getDisplayName() {
105105
* - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
106106
* example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
107107
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped
108+
* - 'limit' - Set a numeric limit for the search results
109+
* - 'offset' - Set the offset for the limited search results
108110
* @return array an array of contacts which are arrays of key-value-pairs
109111
* example result:
110112
* [

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,12 @@ public function search($addressBookId, $pattern, $searchProperties, $options = [
965965
$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
966966
}
967967
}
968+
if (isset($options['limit'])) {
969+
$query2->setMaxResults($options['limit']);
970+
}
971+
if (isset($options['offset'])) {
972+
$query2->setFirstResult($options['offset']);
973+
}
968974

969975
$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
970976
->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL())));

lib/private/Collaboration/Collaborators/MailPlugin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
8181
$emailType = new SearchResultType('emails');
8282

8383
// Search in contacts
84-
//@todo Pagination missing
85-
$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
84+
$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN'], ['limit' => $limit, 'offset' => $offset]);
8685
$lowerSearch = strtolower($search);
8786
foreach ($addressBookContacts as $contact) {
8887
if (isset($contact['EMAIL'])) {

lib/private/Collaboration/Collaborators/RemotePlugin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
6767
$resultType = new SearchResultType('remotes');
6868

6969
// Search in contacts
70-
//@todo Pagination missing
71-
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
70+
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], ['limit' => $limit, 'offset' => $offset]);
7271
foreach ($addressBookContacts as $contact) {
7372
if (isset($contact['isLocalSystemBook'])) {
7473
continue;

lib/private/ContactsManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class ContactsManager implements \OCP\Contacts\IManager {
4040
* @param array $searchProperties defines the properties within the query pattern should match
4141
* @param array $options = array() to define the search behavior
4242
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped
43+
* - 'limit' - Set a numeric limit for the search results
44+
* - 'offset' - Set the offset for the limited search results
4345
* @return array an array of contacts which are arrays of key-value-pairs
4446
*/
4547
public function search($pattern, $searchProperties = [], $options = []) {

lib/public/Contacts/IManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ interface IManager {
9696
* @param array $searchProperties defines the properties within the query pattern should match
9797
* @param array $options = array() to define the search behavior
9898
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped
99+
* - 'limit' - Set a numeric limit for the search results
100+
* - 'offset' - Set the offset for the limited search results
99101
* @return array an array of contacts which are arrays of key-value-pairs
100102
* @since 6.0.0
101103
*/

lib/public/IAddressBook.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function getDisplayName();
7171
* - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
7272
* example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
7373
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped
74+
* - 'limit' - Set a numeric limit for the search results
75+
* - 'offset' - Set the offset for the limited search results
7476
* @return array an array of contacts which are arrays of key-value-pairs
7577
* example result:
7678
* [

0 commit comments

Comments
 (0)