mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
feat: add pagination compatibility to cardav backend
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
This commit is contained in:
parent
897c341c5d
commit
02418d5835
2 changed files with 20 additions and 5 deletions
|
|
@ -157,7 +157,9 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable, IMov
|
|||
}
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -469,13 +469,26 @@ class CardDavBackend implements BackendInterface, SyncSupport {
|
|||
* 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 = [];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue