Renamed some visits paginator adapters for consistency

This commit is contained in:
Alejandro Celaya 2022-01-10 20:26:33 +01:00
parent b438802e71
commit db4ef328b1
9 changed files with 26 additions and 22 deletions

View File

@ -23,7 +23,7 @@ class OrphanVisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapte
)); ));
} }
public function getSlice($offset, $length): iterable // phpcs:ignore public function getSlice(int $offset, int $length): iterable
{ {
return $this->repo->findOrphanVisits(new VisitsListFiltering( return $this->repo->findOrphanVisits(new VisitsListFiltering(
$this->params->getDateRange(), $this->params->getDateRange(),

View File

@ -18,7 +18,7 @@ class ShortUrlRepositoryAdapter implements AdapterInterface
) { ) {
} }
public function getSlice($offset, $length): array // phpcs:ignore public function getSlice(int $offset, int $length): iterable
{ {
return $this->repository->findList( return $this->repository->findList(
$length, $length,

View File

@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering;
class VisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter class ShortUrlVisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter
{ {
public function __construct( public function __construct(
private VisitRepositoryInterface $visitRepository, private VisitRepositoryInterface $visitRepository,
@ -21,7 +21,7 @@ class VisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter
) { ) {
} }
public function getSlice($offset, $length): array // phpcs:ignore public function getSlice(int $offset, int $length): iterable
{ {
return $this->visitRepository->findVisitsByShortCode( return $this->visitRepository->findVisitsByShortCode(
$this->identifier, $this->identifier,

View File

@ -10,7 +10,7 @@ use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter class TagVisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter
{ {
public function __construct( public function __construct(
private VisitRepositoryInterface $visitRepository, private VisitRepositoryInterface $visitRepository,
@ -20,7 +20,7 @@ class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapte
) { ) {
} }
public function getSlice($offset, $length): array // phpcs:ignore public function getSlice(int $offset, int $length): iterable
{ {
return $this->visitRepository->findVisitsByTag( return $this->visitRepository->findVisitsByTag(
$this->tag, $this->tag,

View File

@ -53,10 +53,7 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
public function findAllVisits(int $blockSize = self::DEFAULT_BLOCK_SIZE): iterable public function findAllVisits(int $blockSize = self::DEFAULT_BLOCK_SIZE): iterable
{ {
$qb = $this->getEntityManager()->createQueryBuilder(); $qb = $this->createQueryBuilder('v');
$qb->select('v')
->from(Visit::class, 'v');
return $this->visitsIterableForQuery($qb, $blockSize); return $this->visitsIterableForQuery($qb, $blockSize);
} }
@ -189,11 +186,13 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void
{ {
$conn = $this->getEntityManager()->getConnection();
if ($dateRange?->startDate() !== null) { if ($dateRange?->startDate() !== null) {
$qb->andWhere($qb->expr()->gte('v.date', '\'' . $dateRange->startDate()->toDateTimeString() . '\'')); $qb->andWhere($qb->expr()->gte('v.date', $conn->quote($dateRange->startDate()->toDateTimeString())));
} }
if ($dateRange?->endDate() !== null) { if ($dateRange?->endDate() !== null) {
$qb->andWhere($qb->expr()->lte('v.date', '\'' . $dateRange->endDate()->toDateTimeString() . '\'')); $qb->andWhere($qb->expr()->lte('v.date', $conn->quote($dateRange->endDate()->toDateTimeString())));
} }
} }

View File

@ -52,5 +52,10 @@ interface VisitRepositoryInterface extends ObjectRepository, EntitySpecification
public function countOrphanVisits(VisitsCountFiltering $filtering): int; public function countOrphanVisits(VisitsCountFiltering $filtering): int;
// /**
// * @return Visit[]
// */
// public function findExistingVisits(VisitsListFiltering $filtering): array;
public function countVisits(?ApiKey $apiKey = null): int; public function countVisits(?ApiKey $apiKey = null): int;
} }

View File

@ -15,8 +15,8 @@ use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Model\VisitsParams;
use Shlinkio\Shlink\Core\Paginator\Adapter\OrphanVisitsPaginatorAdapter; use Shlinkio\Shlink\Core\Paginator\Adapter\OrphanVisitsPaginatorAdapter;
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsForTagPaginatorAdapter; use Shlinkio\Shlink\Core\Paginator\Adapter\ShortUrlVisitsPaginatorAdapter;
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsPaginatorAdapter; use Shlinkio\Shlink\Core\Paginator\Adapter\TagVisitsPaginatorAdapter;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface;
use Shlinkio\Shlink\Core\Repository\TagRepository; use Shlinkio\Shlink\Core\Repository\TagRepository;
use Shlinkio\Shlink\Core\Repository\VisitRepository; use Shlinkio\Shlink\Core\Repository\VisitRepository;
@ -62,7 +62,7 @@ class VisitsStatsHelper implements VisitsStatsHelperInterface
/** @var VisitRepositoryInterface $repo */ /** @var VisitRepositoryInterface $repo */
$repo = $this->em->getRepository(Visit::class); $repo = $this->em->getRepository(Visit::class);
return $this->createPaginator(new VisitsPaginatorAdapter($repo, $identifier, $params, $spec), $params); return $this->createPaginator(new ShortUrlVisitsPaginatorAdapter($repo, $identifier, $params, $spec), $params);
} }
/** /**
@ -80,7 +80,7 @@ class VisitsStatsHelper implements VisitsStatsHelperInterface
/** @var VisitRepositoryInterface $repo */ /** @var VisitRepositoryInterface $repo */
$repo = $this->em->getRepository(Visit::class); $repo = $this->em->getRepository(Visit::class);
return $this->createPaginator(new VisitsForTagPaginatorAdapter($repo, $tag, $params, $apiKey), $params); return $this->createPaginator(new TagVisitsPaginatorAdapter($repo, $tag, $params, $apiKey), $params);
} }
/** /**

View File

@ -9,7 +9,7 @@ use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Model\VisitsParams;
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsForTagPaginatorAdapter; use Shlinkio\Shlink\Core\Paginator\Adapter\TagVisitsPaginatorAdapter;
use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface; use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering;
@ -63,9 +63,9 @@ class VisitsForTagPaginatorAdapterTest extends TestCase
$countVisits->shouldHaveBeenCalledOnce(); $countVisits->shouldHaveBeenCalledOnce();
} }
private function createAdapter(?ApiKey $apiKey): VisitsForTagPaginatorAdapter private function createAdapter(?ApiKey $apiKey): TagVisitsPaginatorAdapter
{ {
return new VisitsForTagPaginatorAdapter( return new TagVisitsPaginatorAdapter(
$this->repo->reveal(), $this->repo->reveal(),
'foo', 'foo',
VisitsParams::fromRawData([]), VisitsParams::fromRawData([]),

View File

@ -10,7 +10,7 @@ use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Model\VisitsParams;
use Shlinkio\Shlink\Core\Paginator\Adapter\VisitsPaginatorAdapter; use Shlinkio\Shlink\Core\Paginator\Adapter\ShortUrlVisitsPaginatorAdapter;
use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface; use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering;
@ -64,9 +64,9 @@ class VisitsPaginatorAdapterTest extends TestCase
$countVisits->shouldHaveBeenCalledOnce(); $countVisits->shouldHaveBeenCalledOnce();
} }
private function createAdapter(?ApiKey $apiKey): VisitsPaginatorAdapter private function createAdapter(?ApiKey $apiKey): ShortUrlVisitsPaginatorAdapter
{ {
return new VisitsPaginatorAdapter( return new ShortUrlVisitsPaginatorAdapter(
$this->repo->reveal(), $this->repo->reveal(),
new ShortUrlIdentifier(''), new ShortUrlIdentifier(''),
VisitsParams::fromRawData([]), VisitsParams::fromRawData([]),