Created DB-level paginator for tags with stats

This commit is contained in:
Alejandro Celaya
2022-01-05 23:44:14 +01:00
parent 3dd4e33758
commit 4b90cf93d3
6 changed files with 36 additions and 12 deletions

View File

@@ -32,14 +32,20 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
/**
* @return TagInfo[]
*/
public function findTagsWithInfo(?ApiKey $apiKey = null): array
{
public function findTagsWithInfo(
?int $limit = null,
?int $offset = null,
?string $searchTerm = null,
?ApiKey $apiKey = null,
): array {
$qb = $this->createQueryBuilder('t');
$qb->select('t AS tag', 'COUNT(DISTINCT s.id) AS shortUrlsCount', 'COUNT(DISTINCT v.id) AS visitsCount')
->leftJoin('t.shortUrls', 's')
->leftJoin('s.visits', 'v')
->groupBy('t')
->orderBy('t.name', 'ASC');
->orderBy('t.name', 'ASC')
->setMaxResults($limit)
->setFirstResult($offset);
if ($apiKey !== null) {
$this->applySpecification($qb, $apiKey->spec(false, 'shortUrls'), 't');

View File

@@ -16,7 +16,12 @@ interface TagRepositoryInterface extends ObjectRepository, EntitySpecificationRe
/**
* @return TagInfo[]
*/
public function findTagsWithInfo(?ApiKey $apiKey = null): array;
public function findTagsWithInfo(
?int $limit = null,
?int $offset = null,
?string $searchTerm = null,
?ApiKey $apiKey = null,
): array;
public function tagExists(string $tag, ?ApiKey $apiKey = null): bool;
}