aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2023-11-14 19:04:35 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-11-15 14:48:55 +0100
commit5cdbd10327e73e5d2896921f46dcadec73445022 (patch)
tree7b558d47aa9e1104368128d27f2505670cd37fc7 /apps/dav/lib/CardDAV
parentcb4e367a22232f2ad2f92b924577c7cddb76877e (diff)
downloadnextcloud-server-5cdbd10327e73e5d2896921f46dcadec73445022.tar.gz
nextcloud-server-5cdbd10327e73e5d2896921f46dcadec73445022.zip
refactor(caldav): Use even earlier return and SQL's WHERE IN
* Early return can operate on the input array * SQL can check be used to check for address book ID inclusion Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php19
1 files changed, 6 insertions, 13 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 9a05abed049..8be0bd8050c 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -1106,7 +1106,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
}
/**
- * @param array $addressBookIds
+ * @param int[] $addressBookIds
* @param string $pattern
* @param array $searchProperties
* @param array $options
@@ -1126,19 +1126,11 @@ class CardDavBackend implements BackendInterface, SyncSupport {
string $pattern,
array $searchProperties,
array $options = []): array {
- $escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
- $useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false;
-
- $query2 = $this->db->getQueryBuilder();
-
- $addressBookOr = $query2->expr()->orX();
- foreach ($addressBookIds as $addressBookId) {
- $addressBookOr->add($query2->expr()->eq('cp.addressbookid', $query2->createNamedParameter($addressBookId)));
- }
-
- if ($addressBookOr->count() === 0) {
+ if (empty($addressBookIds)) {
return [];
}
+ $escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
+ $useWildcards = !\array_key_exists('wildcard', $options) || $options['wildcard'] !== false;
if ($escapePattern) {
$searchProperties = array_filter($searchProperties, function ($property) use ($pattern) {
@@ -1161,9 +1153,10 @@ class CardDavBackend implements BackendInterface, SyncSupport {
return [];
}
+ $query2 = $this->db->getQueryBuilder();
$query2->selectDistinct('cp.cardid')
->from($this->dbCardsPropertiesTable, 'cp')
- ->andWhere($addressBookOr)
+ ->where($query2->expr()->in('cp.addressbookid', $query2->createNamedParameter($addressBookIds, IQueryBuilder::PARAM_INT_ARRAY), IQueryBuilder::PARAM_INT_ARRAY))
->andWhere($query2->expr()->in('cp.name', $query2->createNamedParameter($searchProperties, IQueryBuilder::PARAM_STR_ARRAY)));
// No need for like when the pattern is empty