CardDAV REPORT fetches all contacts from the DB.
Nobody has claimed this yet.
- 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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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