mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 00:47:25 -06:00
Add missing COALESCE when summing visits counts
This commit is contained in:
parent
3d7b1ca799
commit
10e941cea6
@ -14,6 +14,11 @@ final readonly class Ordering
|
||||
{
|
||||
}
|
||||
|
||||
public static function none(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{string|null, string|null} $props
|
||||
*/
|
||||
@ -23,11 +28,6 @@ final readonly class Ordering
|
||||
return new self($field, $dir ?? self::DEFAULT_DIR);
|
||||
}
|
||||
|
||||
public static function none(): self
|
||||
{
|
||||
return new self(null, self::DEFAULT_DIR);
|
||||
}
|
||||
|
||||
public static function fromFieldAsc(string $field): self
|
||||
{
|
||||
return new self($field, self::ASC_DIR);
|
||||
|
@ -30,7 +30,7 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
||||
{
|
||||
$buildVisitsSubQuery = function (string $alias, bool $excludingBots): string {
|
||||
$vqb = $this->getEntityManager()->createQueryBuilder();
|
||||
$vqb->select('SUM(' . $alias . '.count)')
|
||||
$vqb->select('COALESCE(SUM(' . $alias . '.count), 0)')
|
||||
->from(ShortUrlVisitsCount::class, $alias)
|
||||
->where($vqb->expr()->eq($alias . '.shortUrl', 's'));
|
||||
|
||||
@ -50,7 +50,7 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
||||
->setMaxResults($filtering->limit)
|
||||
->setFirstResult($filtering->offset)
|
||||
// This param is used in one of the sub-queries, but needs to set in the parent query
|
||||
->setParameter('potentialBot', 0);
|
||||
->setParameter('potentialBot', false);
|
||||
|
||||
$this->processOrderByForList($qb, $filtering);
|
||||
|
||||
|
@ -128,7 +128,7 @@ final class ShortUrlVisitsCountTracker
|
||||
$qb->expr()->eq('slot_id', ':slot_id'),
|
||||
))
|
||||
->setParameter('short_url_id', $shortUrlId)
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('potential_bot', $potentialBot ? '1' : '0')
|
||||
->setParameter('slot_id', $slotId)
|
||||
->setMaxResults(1);
|
||||
|
||||
@ -155,7 +155,7 @@ final class ShortUrlVisitsCountTracker
|
||||
));
|
||||
|
||||
$writeQb->setParameter('short_url_id', $shortUrlId)
|
||||
->setParameter('potential_bot', $potentialBot)
|
||||
->setParameter('potential_bot', $potentialBot ? '1' : '0')
|
||||
->setParameter('slot_id', $slotId)
|
||||
->executeStatement();
|
||||
}
|
||||
|
@ -115,12 +115,11 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase
|
||||
self::assertCount(3, $result);
|
||||
self::assertSame($bar, $result[0]->shortUrl);
|
||||
|
||||
// FIXME Check why this assertion fails
|
||||
// $result = $this->repo->findList(new ShortUrlsListFiltering(
|
||||
// orderBy: Ordering::fromFieldDesc(OrderableField::NON_BOT_VISITS->value),
|
||||
// ));
|
||||
// self::assertCount(3, $result);
|
||||
// self::assertSame($foo2, $result[0]->shortUrl);
|
||||
$result = $this->repo->findList(new ShortUrlsListFiltering(
|
||||
orderBy: Ordering::fromFieldDesc(OrderableField::NON_BOT_VISITS->value),
|
||||
));
|
||||
self::assertCount(3, $result);
|
||||
self::assertSame($foo2, $result[0]->shortUrl);
|
||||
|
||||
$result = $this->repo->findList(new ShortUrlsListFiltering(
|
||||
dateRange: DateRange::until(Chronos::now()->subDays(2)),
|
||||
|
Loading…
Reference in New Issue
Block a user