mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Merge pull request #784 from acelaya-forks/feature/tag-visits-many-short-urls
Feature/tag visits many short urls
This commit is contained in:
commit
e814f3afcf
4 changed files with 11 additions and 21 deletions
|
@ -46,7 +46,7 @@ before_script:
|
||||||
- export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep Dockerfile)
|
- export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep Dockerfile)
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- if [[ "${DOCKER_PUBLISH}" == 'false' ]]; then composer ci ; fi
|
- if [[ "${DOCKER_PUBLISH}" == 'false' ]]; then bin/test/run-api-tests.sh --coverage-php build/coverage-api.cov && composer ci ; fi
|
||||||
- if [[ ! -z "${DOCKERFILE_CHANGED}" && "${TRAVIS_PHP_VERSION}" == "7.4" && "${DOCKER_PUBLISH}" == "false" ]]; then docker build -t shlink-docker-image:temp . ; fi
|
- if [[ ! -z "${DOCKERFILE_CHANGED}" && "${TRAVIS_PHP_VERSION}" == "7.4" && "${DOCKER_PUBLISH}" == "false" ]]; then docker build -t shlink-docker-image:temp . ; fi
|
||||||
- if [[ "${DOCKER_PUBLISH}" == 'true' ]]; then bash ./docker/build ; fi
|
- if [[ "${DOCKER_PUBLISH}" == 'true' ]]; then bash ./docker/build ; fi
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
||||||
#### Fixed
|
#### Fixed
|
||||||
|
|
||||||
* [#769](https://github.com/shlinkio/shlink/issues/769) Fixed custom slugs not allowing valid URL characters, like `.`, `_` or `~`.
|
* [#769](https://github.com/shlinkio/shlink/issues/769) Fixed custom slugs not allowing valid URL characters, like `.`, `_` or `~`.
|
||||||
|
* [#781](https://github.com/shlinkio/shlink/issues/781) Fixed memory leak when loading visits for a tag which is used for big amounts of short URLs.
|
||||||
|
|
||||||
|
|
||||||
## 2.2.1 - 2020-05-11
|
## 2.2.1 - 2020-05-11
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
"symfony/filesystem": "^5.1",
|
"symfony/filesystem": "^5.1",
|
||||||
"symfony/lock": "^5.1",
|
"symfony/lock": "^5.1",
|
||||||
"symfony/mercure": "^0.3.0",
|
"symfony/mercure": "^0.3.0",
|
||||||
"symfony/process": "~5.0.9",
|
"symfony/process": "^5.1",
|
||||||
"symfony/string": "^5.1",
|
"symfony/string": "^5.1",
|
||||||
"symfony/translation-contracts": "^2.1"
|
"symfony/translation-contracts": "^2.1"
|
||||||
},
|
},
|
||||||
|
@ -112,8 +112,7 @@
|
||||||
],
|
],
|
||||||
"test:ci": [
|
"test:ci": [
|
||||||
"@test:unit:ci",
|
"@test:unit:ci",
|
||||||
"@test:db",
|
"@test:db"
|
||||||
"@test:api:ci"
|
|
||||||
],
|
],
|
||||||
"test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
|
"test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
|
||||||
"test:unit:ci": "@test:unit --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/junit.xml",
|
"test:unit:ci": "@test:unit --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/junit.xml",
|
||||||
|
|
|
@ -12,8 +12,6 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
use Shlinkio\Shlink\Core\Entity\VisitLocation;
|
||||||
|
|
||||||
use function array_column;
|
|
||||||
|
|
||||||
use const PHP_INT_MAX;
|
use const PHP_INT_MAX;
|
||||||
|
|
||||||
class VisitRepository extends EntityRepository implements VisitRepositoryInterface
|
class VisitRepository extends EntityRepository implements VisitRepositoryInterface
|
||||||
|
@ -142,26 +140,18 @@ class VisitRepository extends EntityRepository implements VisitRepositoryInterfa
|
||||||
|
|
||||||
private function createVisitsByTagQueryBuilder(string $tag, ?DateRange $dateRange = null): QueryBuilder
|
private function createVisitsByTagQueryBuilder(string $tag, ?DateRange $dateRange = null): QueryBuilder
|
||||||
{
|
{
|
||||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
|
||||||
$qb->select('s.id')
|
|
||||||
->from(ShortUrl::class, 's')
|
|
||||||
->join('s.tags', 't')
|
|
||||||
->where($qb->expr()->eq('t.name', ':tag'))
|
|
||||||
->setParameter('tag', $tag);
|
|
||||||
|
|
||||||
$shortUrlIds = array_column($qb->getQuery()->getArrayResult(), 'id');
|
|
||||||
$shortUrlIds[] = '-1'; // Add an invalid ID, in case the list is empty
|
|
||||||
|
|
||||||
// Parameters in this query need to be part of the query itself, as we need to use it a sub-query later
|
// Parameters in this query need to be part of the query itself, as we need to use it a sub-query later
|
||||||
// Since they are not strictly provided by the caller, it's reasonably safe
|
// Since they are not strictly provided by the caller, it's reasonably safe
|
||||||
$qb2 = $this->getEntityManager()->createQueryBuilder();
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||||
$qb2->from(Visit::class, 'v')
|
$qb->from(Visit::class, 'v')
|
||||||
->where($qb2->expr()->in('v.shortUrl', $shortUrlIds));
|
->join('v.shortUrl', 's')
|
||||||
|
->join('s.tags', 't')
|
||||||
|
->where($qb->expr()->eq('t.name', '\'' . $tag . '\''));
|
||||||
|
|
||||||
// Apply date range filtering
|
// Apply date range filtering
|
||||||
$this->applyDatesInline($qb2, $dateRange);
|
$this->applyDatesInline($qb, $dateRange);
|
||||||
|
|
||||||
return $qb2;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void
|
private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void
|
||||||
|
|
Loading…
Add table
Reference in a new issue