From c7239aaca2516e42c87608d151b8fc88e4df1b2d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya <alejandro@alejandrocelaya.com> Date: Sat, 4 Aug 2018 16:15:09 +0200 Subject: [PATCH] Fixed duplicated join with same table performed while filtering short codes by search term and tags --- docs/swagger/paths/v1_short-codes.json | 2 +- module/Core/src/Repository/ShortUrlRepository.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/swagger/paths/v1_short-codes.json b/docs/swagger/paths/v1_short-codes.json index 9d52f798..f377e67c 100644 --- a/docs/swagger/paths/v1_short-codes.json +++ b/docs/swagger/paths/v1_short-codes.json @@ -25,7 +25,7 @@ } }, { - "name": "tags", + "name": "tags[]", "in": "query", "description": "A list of tags used to filter the resultset. Only short URLs tagged with at least one of the provided tags will be returned. (Since v1.3.0)", "required": false, diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index 04a5b6e6..42b2c73e 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -93,7 +93,10 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI // Apply search term to every searchable field if not empty if (! empty($searchTerm)) { - $qb->leftJoin('s.tags', 't'); + // Left join with tags only if no tags were provided. In case of tags, an inner join will be done later + if (empty($tags)) { + $qb->leftJoin('s.tags', 't'); + } $conditions = [ $qb->expr()->like('s.originalUrl', ':searchPattern'),