nextcloud / nextcloud/server

CardDAV REPORT fetches all contacts from the DB.

Open
#33,147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage enhancement feature: carddav performance 🚀
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Is your feature request related to a problem? Please describe. I am trying to fetch a user from a user's address book via email address.

curl -iXREPORT https://nextcloud.example/remote.php/dav/addressbooks/users/$user/contacts --data-binary '<?xml version="1.0" encoding="utf-8"?>
<addressbook-query xmlns="urn:ietf:params:xml:ns:carddav">
  <filter>
    <prop-filter name="EMAIL">
      <text-match match-type="equals">me@example</text-match>
    </prop-filter>
  </filter>
  <limit><nresults>1</nresults></limit>
</addressbook-query>'

Now this works, but it is very slow. If I look at the database queries executed I see that the following is run:

SELECT "id", "uri", "lastmodified", "etag", "size", "carddata", "uid" FROM "oc_cards" WHERE "addressbookid" = $1

That isn't good for performance. Ideally I would like to see something like the following which uses the oc_cards_properties index.

SELECT oc_cards."id", "uri", "lastmodified", "etag", "size", "carddata", "uid"
FROM oc_cards_properties
JOIN oc_cards ON oc_cards_properties.cardid = oc_cards.id
WHERE name = 'EMAIL'
AND value = 'me@example';
LIMIT 1

This behaviour appears to come from sabredav

https://github.com/sabre-io/dav/blob/b65362abc926520eda2c57e219f022a6c288069d/lib/CardDAV/Plugin.php#L398-L471

I don't know exactly the architecture of sabre and nextcloud so either that method needs to be overwritten to do better filtering or it needs to push down the filters to the provider.

Describe the solution you'd like
Simple lookups should use the oc_cards_properties index or something similar.

Describe alternatives you've considered
A different API for contacts searches? I couldn't find one and it would be nice to use the standard CardDAV API.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with sabre/dav/lib/CardDAV/Plugin.php around lines 398-471, then trace how Nextcloud supplies address-book card data. Compare the current full oc_cards query with filtering through oc_cards_properties. Done means simple CardDAV REPORT lookups can use the indexed property data without fetching every contact.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend, database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.