]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use paginated search for contacts 18816/head
authorJulius Härtl <jus@bitgrid.net>
Fri, 10 Jan 2020 15:06:44 +0000 (16:06 +0100)
committerJulius Härtl <jus@bitgrid.net>
Thu, 23 Apr 2020 17:08:16 +0000 (19:08 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/dav/lib/CardDAV/AddressBookImpl.php
apps/dav/lib/CardDAV/CardDavBackend.php
lib/private/Collaboration/Collaborators/MailPlugin.php
lib/private/Collaboration/Collaborators/RemotePlugin.php
lib/private/ContactsManager.php
lib/public/Contacts/IManager.php
lib/public/IAddressBook.php

index 5e355611c11d34d25e20a8b50fefc25450fad3ba..3eea0f1d5c8949843fd0912a85777c7e5df5fa62 100644 (file)
@@ -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:
         *  [
index f4de1b717fb139a747279995a01fc45638294e3e..87e8e11cd167daeaab9a81af0677219a71d50c08 100644 (file)
@@ -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())));
index e387e38c6dc9a5d2711a6480c548995e80ba25ee..8266ca6794f1d66dff386385df1fbfd491b63679 100644 (file)
@@ -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'])) {
index 6309b8e6eab4d705c836bade8454f6b736cf94fa..e4340f4c19b6741288aaa067492fcabb6138acf0 100644 (file)
@@ -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;
index c28e7f6ad4bdee13f0d15c2488739173bb03bcca..fca0a6e5ba3d9f2c172e922a19c7376e03b60ea6 100644 (file)
@@ -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 = []) {
index dcb4c7ddbb33a77d25784af84fe576c1458316d1..e0551bcd9dd93c2b9d900519fb18d6f7fd023a45 100644 (file)
@@ -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
         */
index 0bce0f44dc044c7a44204c5c5987217abe3880b5..b2c9a103c2cf55808fe2af6b97666b52a4a4cc16 100644 (file)
@@ -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:
                 *  [