mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #41474 from nextcloud/refactor/carddav/earlier-return-sql-where-in
refactor(carddav): Use even earlier return and SQL's WHERE IN
This commit is contained in:
commit
d06ee45b80
1 changed files with 6 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue