mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-12 16:39:35 +03:00
feat: make preloading of CIDR asynchronous at application startup
This commit is contained in:
@@ -49,6 +49,7 @@ class IPListService {
|
||||
EventLoop::queue(function () {
|
||||
foreach ($this->sites as $siteEntity) {
|
||||
if ($siteEntity->timeout) {
|
||||
$siteEntity->preload();
|
||||
$siteEntity->reload();
|
||||
delay(1);
|
||||
}
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user