From 6709833dc7248fe448b6b809584d9a2e9546af7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 10 Jan 2020 16:06:44 +0100 Subject: [PATCH] Use paginated search for contacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/dav/lib/CardDAV/AddressBookImpl.php | 2 ++ apps/dav/lib/CardDAV/CardDavBackend.php | 6 ++++++ lib/private/Collaboration/Collaborators/MailPlugin.php | 3 +-- lib/private/Collaboration/Collaborators/RemotePlugin.php | 3 +-- lib/private/ContactsManager.php | 2 ++ lib/public/Contacts/IManager.php | 2 ++ lib/public/IAddressBook.php | 2 ++ 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 5e355611c1..3eea0f1d5c 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -105,6 +105,8 @@ class AddressBookImpl implements IAddressBook { * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']] * - 'escape_like_param' - If set to false wildcards _ and % are not escaped + * - 'limit' - Set a numeric limit for the search results + * - 'offset' - Set the offset for the limited search results * @return array an array of contacts which are arrays of key-value-pairs * example result: * [ diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index f4de1b717f..87e8e11cd1 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -965,6 +965,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); } } + if (isset($options['limit'])) { + $query2->setMaxResults($options['limit']); + } + if (isset($options['offset'])) { + $query2->setFirstResult($options['offset']); + } $query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c') ->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL()))); diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index e387e38c6d..8266ca6794 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -81,8 +81,7 @@ class MailPlugin implements ISearchPlugin { $emailType = new SearchResultType('emails'); // Search in contacts - //@todo Pagination missing - $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); + $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN'], ['limit' => $limit, 'offset' => $offset]); $lowerSearch = strtolower($search); foreach ($addressBookContacts as $contact) { if (isset($contact['EMAIL'])) { diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index 6309b8e6ea..e4340f4c19 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -67,8 +67,7 @@ class RemotePlugin implements ISearchPlugin { $resultType = new SearchResultType('remotes'); // Search in contacts - //@todo Pagination missing - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']); + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], ['limit' => $limit, 'offset' => $offset]); foreach ($addressBookContacts as $contact) { if (isset($contact['isLocalSystemBook'])) { continue; diff --git a/lib/private/ContactsManager.php b/lib/private/ContactsManager.php index c28e7f6ad4..fca0a6e5ba 100644 --- a/lib/private/ContactsManager.php +++ b/lib/private/ContactsManager.php @@ -40,6 +40,8 @@ namespace OC { * @param array $searchProperties defines the properties within the query pattern should match * @param array $options = array() to define the search behavior * - 'escape_like_param' - If set to false wildcards _ and % are not escaped + * - 'limit' - Set a numeric limit for the search results + * - 'offset' - Set the offset for the limited search results * @return array an array of contacts which are arrays of key-value-pairs */ public function search($pattern, $searchProperties = [], $options = []) { diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php index dcb4c7ddbb..e0551bcd9d 100644 --- a/lib/public/Contacts/IManager.php +++ b/lib/public/Contacts/IManager.php @@ -96,6 +96,8 @@ interface IManager { * @param array $searchProperties defines the properties within the query pattern should match * @param array $options = array() to define the search behavior * - 'escape_like_param' - If set to false wildcards _ and % are not escaped + * - 'limit' - Set a numeric limit for the search results + * - 'offset' - Set the offset for the limited search results * @return array an array of contacts which are arrays of key-value-pairs * @since 6.0.0 */ diff --git a/lib/public/IAddressBook.php b/lib/public/IAddressBook.php index 0bce0f44dc..b2c9a103c2 100644 --- a/lib/public/IAddressBook.php +++ b/lib/public/IAddressBook.php @@ -71,6 +71,8 @@ namespace OCP { * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']] * - 'escape_like_param' - If set to false wildcards _ and % are not escaped + * - 'limit' - Set a numeric limit for the search results + * - 'offset' - Set the offset for the limited search results * @return array an array of contacts which are arrays of key-value-pairs * example result: * [