diff --git a/src/Console/Commands/StaticWarm.php b/src/Console/Commands/StaticWarm.php index 03e33da0b5..909d6043ce 100644 --- a/src/Console/Commands/StaticWarm.php +++ b/src/Console/Commands/StaticWarm.php @@ -41,6 +41,7 @@ class StaticWarm extends Command {--max-depth= : Maximum depth of URLs to warm} {--include= : Only warm specific URLs} {--exclude= : Exclude specific URLs} + {--max-requests= : Maximum number of requests to warm} '; protected $description = 'Warms the static cache by visiting all URLs'; @@ -195,7 +196,8 @@ private function uris(): Collection return $cacher->isExcluded($uri); }) ->sort() - ->values(); + ->values() + ->when($this->option('max-requests'), fn ($uris, $max) => $uris->take($max)); } private function shouldInclude($uri): bool diff --git a/tests/Console/Commands/StaticWarmTest.php b/tests/Console/Commands/StaticWarmTest.php index bcb7f5fdd8..db9ce453e2 100644 --- a/tests/Console/Commands/StaticWarmTest.php +++ b/tests/Console/Commands/StaticWarmTest.php @@ -141,6 +141,16 @@ public function it_respects_max_depth() ->assertExitCode(0); } + #[Test] + public function it_limits_the_number_of_requests_when_max_requests_is_set() + { + config(['statamic.static_caching.strategy' => 'half']); + + $this->artisan('statamic:static:warm', ['--max-requests' => 1]) + ->expectsOutput('Visiting 1 URLs...') + ->assertExitCode(0); + } + #[Test] public function it_doesnt_queue_the_requests_when_connection_is_set_to_sync() {