feat: use domainPurchase to get stats

This commit is contained in:
Maël Gangloff 2025-11-01 18:52:41 +01:00
parent 4f6b8d5b97
commit 29db54ad17
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
4 changed files with 23 additions and 28 deletions

View File

@ -95,7 +95,7 @@ export default function StatisticsPage() {
<Statistic
loading={stats === undefined}
title={t`Success rate`}
value={successRate === undefined ? '-' : successRate * 100}
value={successRate === undefined ? '-' : (successRate * 100).toFixed(2)}
suffix='%'
valueStyle={{color: successRate === undefined ? 'grey' : successRate >= 0.5 ? 'darkgreen' : 'orange'}}
/>

View File

@ -3,6 +3,7 @@
namespace App\Controller;
use App\Entity\Statistics;
use App\Repository\DomainPurchaseRepository;
use App\Repository\DomainRepository;
use App\Repository\WatchlistRepository;
use Psr\Cache\CacheItemPoolInterface;
@ -16,6 +17,7 @@ class StatisticsController extends AbstractController
private readonly CacheItemPoolInterface $pool,
private readonly DomainRepository $domainRepository,
private readonly WatchlistRepository $watchlistRepository,
private readonly DomainPurchaseRepository $domainPurchaseRepository,
private readonly KernelInterface $kernel,
) {
}
@ -29,8 +31,12 @@ class StatisticsController extends AbstractController
$stats
->setRdapQueries($this->pool->getItem('stats.rdap_queries.count')->get() ?? 0)
->setDomainPurchased($this->pool->getItem('stats.domain.purchased')->get() ?? 0)
->setDomainPurchaseFailed($this->pool->getItem('stats.domain.purchase.failed')->get() ?? 0)
->setDomainPurchased(
$this->getCachedItem('stats.domain.purchase', fn () => $this->domainPurchaseRepository->count())
)
->setDomainPurchaseFailed(
$this->getCachedItem('stats.domain.purchase.failed', fn () => $this->domainPurchaseRepository->countFailDomainPurchase())
)
->setAlertSent($this->pool->getItem('stats.alert.sent')->get() ?? 0)
->setDomainTracked(

View File

@ -109,7 +109,6 @@ final readonly class OrderDomainHandler
'provider' => $connector->getProvider()->value,
]);
$this->statService->incrementStat('stats.domain.purchased');
if ($this->influxdbEnabled) {
$this->influxdbService->addDomainOrderPoint($connector, $domain, true);
}
@ -138,7 +137,6 @@ final readonly class OrderDomainHandler
'provider' => $connector->getProvider()->value,
]);
$this->statService->incrementStat('stats.domain.purchase.failed');
if ($this->influxdbEnabled) {
$this->influxdbService->addDomainOrderPoint($connector, $domain, false);
}

View File

@ -16,28 +16,19 @@ class DomainPurchaseRepository extends ServiceEntityRepository
parent::__construct($registry, DomainPurchase::class);
}
// /**
// * @return DomainPurchase[] Returns an array of DomainPurchase objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('d')
// ->andWhere('d.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('d.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function countSuccessDomainPurchase(): int
{
return $this->createQueryBuilder('dp')
->select('COUNT(*)')
->where('dp.domainOrderedAt != NULL')
->getQuery()->getSingleScalarResult();
}
// public function findOneBySomeField($value): ?DomainPurchase
// {
// return $this->createQueryBuilder('d')
// ->andWhere('d.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
public function countFailDomainPurchase(): int
{
return $this->createQueryBuilder('dp')
->select('COUNT(*)')
->where('dp.domainOrderedAt == NULL')
->getQuery()->getSingleScalarResult();
}
}