Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pagination compatibility to cardav backend #47909

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dav/lib/CardDAV/AddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
}

public function getChildren() {
$objs = $this->carddavBackend->getCards($this->addressBookInfo['id']);
$offset = $_SERVER['HTTP_X_NEXTCLOUD_OFFSET'];
$limit = $_SERVER['HTTP_X_NEXTCLOUD_LIMIT'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to use the standardized limit: https://datatracker.ietf.org/doc/html/rfc6352#section-8.6.1

$objs = $this->carddavBackend->getCards($this->addressBookInfo['id'], $offset, $limit);

Check failure on line 162 in apps/dav/lib/CardDAV/AddressBook.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/dav/lib/CardDAV/AddressBook.php:162:73: InvalidArgument: Argument 2 of OCA\DAV\CardDAV\CardDavBackend::getCards expects int|null, but string provided (see https://psalm.dev/004)

Check failure on line 162 in apps/dav/lib/CardDAV/AddressBook.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/dav/lib/CardDAV/AddressBook.php:162:82: InvalidArgument: Argument 3 of OCA\DAV\CardDAV\CardDavBackend::getCards expects int|null, but string provided (see https://psalm.dev/004)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 2 of OCA\DAV\CardDAV\CardDavBackend::getCards expects int|null, but string provided

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 3 of OCA\DAV\CardDAV\CardDavBackend::getCards expects int|null, but string provided
$children = [];
foreach ($objs as $obj) {
$obj['acl'] = $this->getChildACL();
Expand Down
21 changes: 17 additions & 4 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
Loading