mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-18 10:15:41 +00:00
refactor: optimize getTrackedDomains
This commit is contained in:
parent
2d07dce1ae
commit
4c3820d70e
@ -7,7 +7,7 @@ use App\Entity\DomainEvent;
|
|||||||
use App\Entity\DomainStatus;
|
use App\Entity\DomainStatus;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\WatchList;
|
use App\Entity\WatchList;
|
||||||
use App\Repository\DomainEventRepository;
|
use App\Repository\DomainRepository;
|
||||||
use App\Repository\WatchListRepository;
|
use App\Repository\WatchListRepository;
|
||||||
use App\Service\CalendarService;
|
use App\Service\CalendarService;
|
||||||
use App\Service\RDAPService;
|
use App\Service\RDAPService;
|
||||||
@ -30,8 +30,9 @@ class WatchListController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly WatchListRepository $watchListRepository,
|
private readonly WatchListRepository $watchListRepository,
|
||||||
private readonly DomainEventRepository $domainEventRepository,
|
private readonly RDAPService $RDAPService,
|
||||||
private readonly RDAPService $RDAPService, private readonly CalendarService $calendarService,
|
private readonly CalendarService $calendarService,
|
||||||
|
private readonly DomainRepository $domainRepository,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,19 +108,9 @@ class WatchListController extends AbstractController
|
|||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
$domains = [];
|
$domains = $this->domainRepository->getMyTrackedDomains($user);
|
||||||
/** @var WatchList $watchList */
|
foreach ($domains as $domain) {
|
||||||
foreach ($user->getWatchLists()->getIterator() as $watchList) {
|
$domain->setExpiresInDays($this->RDAPService->getExpiresInDays($domain));
|
||||||
/** @var Domain $domain */
|
|
||||||
foreach ($watchList->getDomains()->getIterator() as $domain) {
|
|
||||||
/** @var DomainEvent|null $exp */
|
|
||||||
$exp = $this->domainEventRepository->findLastDomainEvent($domain, 'expiration');
|
|
||||||
|
|
||||||
if (!$domain->getDeleted() && null !== $exp && !in_array($domain, $domains)) {
|
|
||||||
$domain->setExpiresInDays($this->RDAPService->getExpiresInDays($domain));
|
|
||||||
$domains[] = $domain;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($domains, fn (Domain $d1, Domain $d2) => $d1->getExpiresInDays() - $d2->getExpiresInDays());
|
usort($domains, fn (Domain $d1, Domain $d2) => $d1->getExpiresInDays() - $d2->getExpiresInDays());
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace App\Repository;
|
|||||||
|
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use App\Entity\Tld;
|
use App\Entity\Tld;
|
||||||
|
use App\Entity\User;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
@ -51,6 +52,22 @@ class DomainRepository extends ServiceEntityRepository
|
|||||||
->getQuery()->execute();
|
->getQuery()->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMyTrackedDomains(User $user): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('d')
|
||||||
|
->select('d')
|
||||||
|
->distinct()
|
||||||
|
->join('d.watchLists', 'w')
|
||||||
|
->join('d.events', 'de')
|
||||||
|
->where('w.user = :user')
|
||||||
|
->andWhere('d.deleted = false')
|
||||||
|
->andWhere("de.action = 'expiration'")
|
||||||
|
->andWhere('de.deleted = false')
|
||||||
|
->getQuery()
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return Domain[] Returns an array of Domain objects
|
// * @return Domain[] Returns an array of Domain objects
|
||||||
// */
|
// */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user