Skip to content

Commit

Permalink
[5.x] Add --max-requests option to the static warm command (#11278)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
arthurperton and jasonvarga authored Dec 18, 2024
1 parent 78299c9 commit 2623efe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Console/Commands/StaticWarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/Console/Commands/StaticWarmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 2623efe

Please sign in to comment.