Skip to content

Commit c41a99b

Browse files
committed
Use paginated search for contacts
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 4b28da1 commit c41a99b

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
@@ -106,6 +106,8 @@ public function getDisplayName() {
106106
* - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
107107
* example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
108108
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped
109+
* - 'limit' - Set a numeric limit for the search results
110+
* - 'offset' - Set the offset for the limited search results
109111
* @return array an array of contacts which are arrays of key-value-pairs
110112
* example result:
111113
* [

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,12 @@ public function search($addressBookId, $pattern, $searchProperties, $options = a
929929
$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
930930
}
931931
}
932+
if(\array_key_exists('limit', $options)) {
933+
$query2->setMaxResults($options['limit']);
934+
}
935+
if(\array_key_exists('offset', $options)) {
936+
$query2->setFirstResult($options['offset']);
937+
}
932938

933939
$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
934940
->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
@@ -68,8 +68,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
6868
$resultType = new SearchResultType('remotes');
6969

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

lib/private/ContactsManager.php

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

lib/public/Contacts/IManager.php

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

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)