Skip to content

Commit bde3d21

Browse files
committed
Only look up crawlConcurrency once per crawl
1 parent ac2f2d3 commit bde3d21

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Crawler.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Crawler {
4242
*/
4343
private $cache_hits = 0;
4444

45+
private int $concurrency;
46+
4547
/**
4648
* @var bool
4749
*/
@@ -213,14 +215,16 @@ function () use ( &$path ) {
213215
}
214216

215217
public function crawlIter( \Iterator $path_iter ): \Iterator {
218+
if ( ! isset( $this->concurrency ) ) {
219+
$this->concurrency = intval( CoreOptions::getValue( 'crawlConcurrency' ) );
220+
}
221+
216222
$site_host = parse_url( $this->site_path, PHP_URL_HOST );
217223
$site_port = parse_url( $this->site_path, PHP_URL_PORT );
218224
$site_host = $site_port ? $site_host . ":$site_port" : $site_host;
219225
$site_urls = [ "http://$site_host", "https://$site_host" ];
220226

221-
$concurrency = intval( CoreOptions::getValue( 'crawlConcurrency' ) );
222227
$in_flight = [];
223-
224228
$start_next = function () use ( &$in_flight, &$path_iter, &$site_urls ) {
225229
$detected = $path_iter->current();
226230
$path = $detected['path'];
@@ -229,7 +233,7 @@ public function crawlIter( \Iterator $path_iter ): \Iterator {
229233
};
230234

231235
$i = 0;
232-
while ( $i++ < $concurrency && $path_iter->valid() ) {
236+
while ( $i++ < $this->concurrency && $path_iter->valid() ) {
233237
$start_next();
234238
}
235239

0 commit comments

Comments
 (0)