summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-27 00:25:30 -0300
committerGitHub <noreply@github.com>2017-04-27 00:25:30 -0300
commit3e37a5f1c742eae03158a14f6dbb1fc3bb1e0a5a (patch)
treea3910375d065a7e15227161efc3e24bd34b99973 /apps/dav/lib/CardDAV
parent4dab01d9ed3da9427dd8ec29bfbe5b436617bd52 (diff)
parent6d1651452f59dfa1e8defca9b37496bc5f07f36c (diff)
downloadnextcloud-server-3e37a5f1c742eae03158a14f6dbb1fc3bb1e0a5a.tar.gz
nextcloud-server-3e37a5f1c742eae03158a14f6dbb1fc3bb1e0a5a.zip
Merge pull request #3770 from nextcloud/faster-search-in-contacts
Factorize query for searching contacts
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php13
1 files changed, 6 insertions, 7 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index cd010b87f08..5deb648fa7f 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -882,16 +882,15 @@ class CardDavBackend implements BackendInterface, SyncSupport {
public function search($addressBookId, $pattern, $searchProperties) {
$query = $this->db->getQueryBuilder();
$query2 = $this->db->getQueryBuilder();
+
$query2->selectDistinct('cp.cardid')->from($this->dbCardsPropertiesTable, 'cp');
+ $query2->andWhere($query2->expr()->eq('cp.addressbookid', $query->createNamedParameter($addressBookId)));
+ $or = $query2->expr()->orX();
foreach ($searchProperties as $property) {
- $query2->orWhere(
- $query2->expr()->andX(
- $query2->expr()->eq('cp.name', $query->createNamedParameter($property)),
- $query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))
- )
- );
+ $or->add($query2->expr()->eq('cp.name', $query->createNamedParameter($property)));
}
- $query2->andWhere($query2->expr()->eq('cp.addressbookid', $query->createNamedParameter($addressBookId)));
+ $query2->andWhere($or);
+ $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL())));