CardDAV REPORT fetches all contacts from the DB. #33147
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.
Activity