mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Improve tags stats performance by using the new short_url_visits_counts table
This commit is contained in:
parent
6ce1550457
commit
071cb9af2b
@ -85,7 +85,7 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->from(ShortUrl::class, 's')
|
||||
->where('1=1');
|
||||
->where('1=1');
|
||||
|
||||
$dateRange = $filtering->dateRange;
|
||||
if ($dateRange?->startDate !== null) {
|
||||
|
@ -76,19 +76,19 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
||||
|
||||
$buildVisitsSubQb = static function (bool $excludeBots, string $aggregateAlias) use ($conn) {
|
||||
$visitsSubQb = $conn->createQueryBuilder();
|
||||
$commonJoinCondition = $visitsSubQb->expr()->eq('v.short_url_id', 's.id');
|
||||
$commonJoinCondition = $visitsSubQb->expr()->eq('sc.short_url_id', 'st.short_url_id');
|
||||
$visitsJoin = ! $excludeBots
|
||||
? $commonJoinCondition
|
||||
: $visitsSubQb->expr()->and(
|
||||
$commonJoinCondition,
|
||||
$visitsSubQb->expr()->eq('v.potential_bot', $conn->quote('0')),
|
||||
$visitsSubQb->expr()->eq('sc.potential_bot', $conn->quote('0')),
|
||||
)->__toString();
|
||||
|
||||
return $visitsSubQb
|
||||
->select('st.tag_id AS tag_id', 'COUNT(DISTINCT v.id) AS ' . $aggregateAlias)
|
||||
->from('visits', 'v')
|
||||
->join('v', 'short_urls', 's', $visitsJoin)
|
||||
->join('s', 'short_urls_in_tags', 'st', $visitsSubQb->expr()->eq('st.short_url_id', 's.id'))
|
||||
->select('st.tag_id AS tag_id', 'SUM(sc.count) AS ' . $aggregateAlias)
|
||||
->from('short_url_visits_counts', 'sc')
|
||||
->join('sc', 'short_urls_in_tags', 'st', $visitsJoin)
|
||||
->join('sc', 'short_urls', 's', $visitsSubQb->expr()->eq('sc.short_url_id', 's.id'))
|
||||
->groupBy('st.tag_id');
|
||||
};
|
||||
$allVisitsSubQb = $buildVisitsSubQb(false, 'visits');
|
||||
|
Loading…
Reference in New Issue
Block a user