feat: reduce IO when registering domains

This commit is contained in:
Maël Gangloff
2024-07-15 00:21:40 +02:00
parent 8a8059a366
commit aa54d4c9ce
2 changed files with 66 additions and 8 deletions

View File

@@ -47,11 +47,22 @@ readonly class RDAPService
/**
* @throws Exception
*/
public function registerDomain(string $fqdn): Domain
public function registerDomains(array $domains): void
{
$dnsRoot = json_decode(file_get_contents($this->params->get('kernel.project_dir') . '/src/Config/dns.json'))->services;
foreach ($domains as $fqdn) {
$this->registerDomain($dnsRoot, $fqdn);
}
}
/**
* @throws Exception
*/
private function registerDomain(array $dnsRoot, string $fqdn): void
{
$idnDomain = idn_to_ascii($fqdn);
try {
$rdapServer = $this->getRDAPServer(RDAPService::getTld($idnDomain));
$rdapServer = $this->getRDAPServer($dnsRoot, RDAPService::getTld($idnDomain));
} catch (Exception) {
throw new Exception("Unable to determine which RDAP server to contact");
}
@@ -156,17 +167,15 @@ readonly class RDAPService
$this->em->persist($domain);
$this->em->flush();
return $domain;
}
/**
* @throws Exception
*/
private function getRDAPServer(string $tld)
private function getRDAPServer(array $dnsRoot, string $tld)
{
$dnsRoot = json_decode(file_get_contents($this->params->get('kernel.project_dir') . '/src/Config/dns.json'))->services;
foreach ($dnsRoot as $dns) {
if (in_array($tld, $dns[0])) return $dns[1][0];
}