diff --git a/apps/dav/lib/CardDAV/AddressBook.php b/apps/dav/lib/CardDAV/AddressBook.php index 2ec645f04d231..3deda7e38a020 100644 --- a/apps/dav/lib/CardDAV/AddressBook.php +++ b/apps/dav/lib/CardDAV/AddressBook.php @@ -157,7 +157,9 @@ public function getChild($name) { } public function getChildren() { - $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); + $offset = $_SERVER['HTTP_X_NEXTCLOUD_OFFSET']; + $limit = $_SERVER['HTTP_X_NEXTCLOUD_LIMIT']; + $objs = $this->carddavBackend->getCards($this->addressBookInfo['id'], $offset, $limit); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 9dee61638a5ab..7c2c8423a2207 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -469,13 +469,26 @@ public function deleteAddressBook($addressBookId) { * This may speed up certain requests, especially with large cards. * * @param mixed $addressbookId + * @param int|null $offset + * @param int|null $limit * @return array */ - public function getCards($addressbookId) { + public function getCards($addressbookId, $offset = null, $limit = null) { $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) - ->from($this->dbCardsTable) - ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressbookId))); + $query->select(['c.id', 'c.uri', 'c.lastmodified', 'c.etag', 'c.size', 'c.carddata', 'c.uid']) + ->from($this->dbCardsTable, 'c') + ->join('c', $this->dbCardsPropertiesTable, 'cp', $query->expr()->eq('cp.cardid', 'c.id')) + ->where($query->expr()->eq('c.addressbookid', $query->createNamedParameter($addressbookId))) + ->andWhere($query->expr()->eq('cp.name', $query->createNamedParameter('FN'))); + + if(isset($offset)) { + $query->orderBy('cp.value'); + $query->setFirstResult($offset); + } + + if(isset($limit)) { + $query->setMaxResults($limit); + } $cards = [];