Skip to content

Commit 1e14ef1

Browse files
committed
Don't use LIKE query when we have the uid
Signed-off-by: Louis Chemineau <[email protected]>
1 parent a1d68c0 commit 1e14ef1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ private function searchByAddressBookIds(array $addressBookIds,
10621062
array $searchProperties,
10631063
array $options = []): array {
10641064
$escapePattern = !\array_key_exists('escape_like_param', $options) || $options['escape_like_param'] !== false;
1065+
$strictSearch = !\array_key_exists('strict_search', $options) || $options['strict_search'] !== false;
10651066

10661067
$query2 = $this->db->getQueryBuilder();
10671068

@@ -1103,10 +1104,18 @@ private function searchByAddressBookIds(array $addressBookIds,
11031104

11041105
// No need for like when the pattern is empty
11051106
if ('' !== $pattern) {
1106-
if (!$escapePattern) {
1107-
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern)));
1107+
if ($strictSearch) {
1108+
if (!$escapePattern) {
1109+
$query2->andWhere( $query2->expr()->eq('cp.value', $query2->createNamedParameter($pattern)));
1110+
} else {
1111+
$query2->andWhere( $query2->expr()->eq('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
1112+
}
11081113
} else {
1109-
$query2->andWhere($query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
1114+
if (!$escapePattern) {
1115+
$query2->andWhere( $query2->expr()->ilike('cp.value', $query2->createNamedParameter($pattern)));
1116+
} else {
1117+
$query2->andWhere( $query2->expr()->ilike('cp.value', $query2->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
1118+
}
11101119
}
11111120
}
11121121

lib/private/Federation/CloudIdManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function resolveCloudId(string $cloudId): ICloudId {
9090
}
9191

9292
protected function getDisplayNameFromContact(string $cloudId): ?string {
93-
$addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD']);
93+
$addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD'], ["strict_search" => true]);
9494
foreach ($addressBookEntries as $entry) {
9595
if (isset($entry['CLOUD'])) {
9696
foreach ($entry['CLOUD'] as $cloudID) {

0 commit comments

Comments
 (0)