Skip to content

Commit 31763e5

Browse files
authored
avoid expensive queries that do not change certain results (#53)
1 parent 053c9df commit 31763e5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Robots.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ public function mayIndex(string $url, ?string $userAgent = null): bool
4141

4242
$robotsTxt = $this->robotsTxt ?? RobotsTxt::create($this->createRobotsUrl($url));
4343

44+
if (! $robotsTxt->allows($url, $userAgent)) {
45+
return false;
46+
}
47+
4448
$content = @file_get_contents($url);
4549

4650
if ($content === false) {
4751
throw new InvalidArgumentException("Could not read url `{$url}`");
4852
}
4953

50-
return
51-
$robotsTxt->allows($url, $userAgent)
52-
&& RobotsMeta::create($content)->mayIndex()
54+
return RobotsMeta::create($content)->mayIndex()
5355
&& RobotsHeaders::create($http_response_header ?? [])->mayIndex();
5456
}
5557

0 commit comments

Comments
 (0)