feat: add stats page

This commit is contained in:
Maël Gangloff
2024-08-22 19:26:34 +02:00
parent 6601540eb4
commit 26ae674117
10 changed files with 174 additions and 43 deletions

View File

@@ -32,21 +32,26 @@ class StatisticsController extends AbstractController
->setDomainPurchased($this->pool->getItem('stats.domain.purchased')->get() ?? 0)
->setDomainPurchaseFailed($this->pool->getItem('stats.domain.purchase.failed')->get() ?? 0)
->setAlertSent($this->pool->getItem('stats.alert.sent')->get() ?? 0)
->setWatchlistCount(
$this->getCachedItem('stats.watchlist.count', fn () => $this->watchListRepository->count()
))
->setDomainTracked(
$this->watchListRepository->createQueryBuilder('w')
->join('w.domains', 'd')
->select('COUNT(DISTINCT d.ldhName)')
->where('d.deleted = FALSE')
->getQuery()->getSingleColumnResult()[0]
)
->setDomainCount(
$this->getCachedItem('stats.domain.count', fn () => $this->domainRepository->createQueryBuilder('d')
->join('d.tld', 't')
->select('t.tld tld')
->addSelect('COUNT(d.ldhName) AS domain')
->addGroupBy('t.tld')
->where('d.deleted = FALSE')
->orderBy('domain', 'DESC')
->setMaxResults(5)
->getQuery()->getArrayResult())
)
->setDomainCountTotal(
$this->getCachedItem('stats.domain.total', fn () => $this->domainRepository->count()
$this->getCachedItem('stats.domain.total', fn () => $this->domainRepository->count(['deleted' => false])
));
return $stats;

View File

@@ -25,8 +25,21 @@ class Statistics
private ?int $domainPurchaseFailed = null;
private ?array $domainCount = null;
private ?int $domainTracked = null;
private ?int $domainCountTotal = null;
private ?int $watchlistCount = null;
public static function updateRDAPQueriesStat(CacheItemPoolInterface $pool, string $key): bool
{
try {
$item = $pool->getItem($key);
$item->set(($item->get() ?? 0) + 1);
return $pool->save($item);
} catch (\Throwable) {
}
return false;
}
public function getRdapQueries(): ?int
{
@@ -76,18 +89,6 @@ class Statistics
return $this;
}
public function getWatchlistCount(): ?int
{
return $this->watchlistCount;
}
public function setWatchlistCount(?int $watchlistCount): static
{
$this->watchlistCount = $watchlistCount;
return $this;
}
public function getDomainCountTotal(): ?int
{
return $this->domainCountTotal;
@@ -110,16 +111,15 @@ class Statistics
return $this;
}
public static function updateRDAPQueriesStat(CacheItemPoolInterface $pool, string $key): bool
public function getDomainTracked(): ?int
{
try {
$item = $pool->getItem($key);
$item->set(($item->get() ?? 0) + 1);
return $this->domainTracked;
}
return $pool->save($item);
} catch (\Throwable) {
}
public function setDomainTracked(?int $domainTracked): static
{
$this->domainTracked = $domainTracked;
return false;
return $this;
}
}