mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
refactor: optimize getTrackedDomains
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Entity\DomainEvent;
|
||||
use App\Entity\DomainStatus;
|
||||
use App\Entity\User;
|
||||
use App\Entity\WatchList;
|
||||
use App\Repository\DomainEventRepository;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Repository\WatchListRepository;
|
||||
use App\Service\CalendarService;
|
||||
use App\Service\RDAPService;
|
||||
@@ -30,8 +30,9 @@ class WatchListController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly WatchListRepository $watchListRepository,
|
||||
private readonly DomainEventRepository $domainEventRepository,
|
||||
private readonly RDAPService $RDAPService, private readonly CalendarService $calendarService,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly CalendarService $calendarService,
|
||||
private readonly DomainRepository $domainRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -107,19 +108,9 @@ class WatchListController extends AbstractController
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$domains = [];
|
||||
/** @var WatchList $watchList */
|
||||
foreach ($user->getWatchLists()->getIterator() as $watchList) {
|
||||
/** @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;
|
||||
}
|
||||
}
|
||||
$domains = $this->domainRepository->getMyTrackedDomains($user);
|
||||
foreach ($domains as $domain) {
|
||||
$domain->setExpiresInDays($this->RDAPService->getExpiresInDays($domain));
|
||||
}
|
||||
|
||||
usort($domains, fn (Domain $d1, Domain $d2) => $d1->getExpiresInDays() - $d2->getExpiresInDays());
|
||||
|
||||
Reference in New Issue
Block a user