feat: make preloading of CIDR asynchronous at application startup

This commit is contained in:
Rekryt
2024-09-22 20:46:54 +03:00
parent 11952303cd
commit 6e42686fc7
3 changed files with 20 additions and 5 deletions

View File

@@ -49,6 +49,7 @@ class IPListService {
EventLoop::queue(function () {
foreach ($this->sites as $siteEntity) {
if ($siteEntity->timeout) {
$siteEntity->preload();
$siteEntity->reload();
delay(1);
}

View File

@@ -44,6 +44,25 @@ final class Site {
$this->dnsHelper = new DNSHelper($dns);
}
/**
* @return void
*/
public function preload(): void {
$startTime = time();
App::getLogger()->notice('Preloading for ' . $this->name, ['started']);
if ($this->timeout) {
$this->cidr4 = SiteFactory::normalize(
IP4Helper::processCIDR($this->ip4, SiteFactory::normalize($this->cidr4)),
true
);
$this->cidr6 = SiteFactory::normalize(
IP6Helper::processCIDR($this->ip6, SiteFactory::normalize($this->cidr6)),
true
);
}
App::getLogger()->notice('Preloaded for ' . $this->name, ['finished', time() - $startTime]);
}
/**
* @return void
*/

View File

@@ -77,11 +77,6 @@ class SiteFactory {
$ip4 = self::normalize($ip4, true);
$ip6 = self::normalize($ip6, true);
if ($timeout) {
$cidr4 = self::normalize(IP4Helper::processCIDR($ip4, self::normalize($cidr4)), true);
$cidr6 = self::normalize(IP6Helper::processCIDR($ip6, self::normalize($cidr6)), true);
}
return new Site($name, $group, $domains, $dns, $timeout, $ip4, $ip6, $cidr4, $cidr6, $external);
}