diff --git a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php index 799b51e9..305042e7 100644 --- a/module/CLI/src/Command/Visit/ProcessVisitsCommand.php +++ b/module/CLI/src/Command/Visit/ProcessVisitsCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; -use function sleep; use function sprintf; class ProcessVisitsCommand extends Command @@ -57,7 +56,6 @@ class ProcessVisitsCommand extends Command $io = new SymfonyStyle($input, $output); $visits = $this->visitService->getUnlocatedVisits(); - $count = 0; foreach ($visits as $visit) { if (! $visit->hasRemoteAddr()) { $io->writeln( @@ -76,7 +74,6 @@ class ProcessVisitsCommand extends Command continue; } - $count++; try { $result = $this->ipLocationResolver->resolveIpLocation($ipAddr); @@ -99,16 +96,6 @@ class ProcessVisitsCommand extends Command $this->getApplication()->renderException($e, $output); } } - - if ($count === $this->ipLocationResolver->getApiLimit()) { - $count = 0; - $seconds = $this->ipLocationResolver->getApiInterval(); - $io->note(sprintf( - $this->translator->translate('IP location resolver limit reached. Waiting %s seconds...'), - $seconds - )); - sleep($seconds); - } } $io->success($this->translator->translate('Finished processing all IPs')); diff --git a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php index e2a36ba6..a92241f0 100644 --- a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; use Zend\I18n\Translator\Translator; use function count; -use function round; class ProcessVisitsCommandTest extends TestCase { @@ -38,7 +37,6 @@ class ProcessVisitsCommandTest extends TestCase { $this->visitService = $this->prophesize(VisitService::class); $this->ipResolver = $this->prophesize(IpApiLocationResolver::class); - $this->ipResolver->getApiLimit()->willReturn(10000000000); $command = new ProcessVisitsCommand( $this->visitService->reveal(), @@ -109,43 +107,4 @@ class ProcessVisitsCommandTest extends TestCase $this->assertContains('Ignored localhost address', $output); $this->assertContains('Ignored visit with no IP address', $output); } - - /** - * @test - */ - public function sleepsEveryTimeTheApiLimitIsReached() - { - $shortUrl = new ShortUrl(''); - - $visits = [ - new Visit($shortUrl, new Visitor('', '', '1.2.3.4')), - new Visit($shortUrl, new Visitor('', '', '4.3.2.1')), - new Visit($shortUrl, new Visitor('', '', '12.34.56.78')), - new Visit($shortUrl, new Visitor('', '', '1.2.3.4')), - new Visit($shortUrl, new Visitor('', '', '4.3.2.1')), - new Visit($shortUrl, new Visitor('', '', '12.34.56.78')), - new Visit($shortUrl, new Visitor('', '', '1.2.3.4')), - new Visit($shortUrl, new Visitor('', '', '4.3.2.1')), - new Visit($shortUrl, new Visitor('', '', '12.34.56.78')), - new Visit($shortUrl, new Visitor('', '', '4.3.2.1')), - ]; - $apiLimit = 3; - - $this->visitService->getUnlocatedVisits()->willReturn($visits); - $this->visitService->saveVisit(Argument::any())->will(function () { - }); - - $getApiLimit = $this->ipResolver->getApiLimit()->willReturn($apiLimit); - $getApiInterval = $this->ipResolver->getApiInterval()->willReturn(0); - $resolveIpLocation = $this->ipResolver->resolveIpLocation(Argument::any())->willReturn([]) - ->shouldBeCalledTimes(count($visits)); - - $this->commandTester->execute([ - 'command' => 'visit:process', - ]); - - $getApiLimit->shouldHaveBeenCalledTimes(count($visits)); - $getApiInterval->shouldHaveBeenCalledTimes(round(count($visits) / $apiLimit)); - $resolveIpLocation->shouldHaveBeenCalledTimes(count($visits)); - } } diff --git a/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php b/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php index 68becdb6..60023ee3 100644 --- a/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php +++ b/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php @@ -50,24 +50,4 @@ class GeoLite2LocationResolver implements IpLocationResolverInterface 'time_zone' => $city->location->timeZone ?? '', ]; } - - /** - * Returns the interval in seconds that needs to be waited when the API limit is reached - * - * @return int - */ - public function getApiInterval(): int - { - return 0; - } - - /** - * Returns the limit of requests that can be performed to the API in a specific interval, or null if no limit exists - * - * @return int|null - */ - public function getApiLimit(): ?int - { - return null; - } } diff --git a/module/Common/src/IpGeolocation/IpApiLocationResolver.php b/module/Common/src/IpGeolocation/IpApiLocationResolver.php index 6bf426bf..fe6680a8 100644 --- a/module/Common/src/IpGeolocation/IpApiLocationResolver.php +++ b/module/Common/src/IpGeolocation/IpApiLocationResolver.php @@ -53,24 +53,4 @@ class IpApiLocationResolver implements IpLocationResolverInterface 'time_zone' => $entry['timezone'] ?? '', ]; } - - /** - * Returns the interval in seconds that needs to be waited when the API limit is reached - * - * @return int - */ - public function getApiInterval(): int - { - return 65; // ip-api interval is 1 minute. Return 5 extra seconds just in case - } - - /** - * Returns the limit of requests that can be performed to the API in a specific interval, or null if no limit exists - * - * @return int|null - */ - public function getApiLimit(): ?int - { - return 145; // ip-api limit is 150 requests per minute. Leave 5 less requests just in case - } } diff --git a/module/Common/src/IpGeolocation/IpLocationResolverInterface.php b/module/Common/src/IpGeolocation/IpLocationResolverInterface.php index 47375e45..f9e41572 100644 --- a/module/Common/src/IpGeolocation/IpLocationResolverInterface.php +++ b/module/Common/src/IpGeolocation/IpLocationResolverInterface.php @@ -13,18 +13,4 @@ interface IpLocationResolverInterface * @throws WrongIpException */ public function resolveIpLocation(string $ipAddress): array; - - /** - * Returns the interval in seconds that needs to be waited when the API limit is reached - * - * @return int - */ - public function getApiInterval(): int; - - /** - * Returns the limit of requests that can be performed to the API in a specific interval, or null if no limit exists - * - * @return int|null - */ - public function getApiLimit(): ?int; }