Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add --max-requests option to the static warm command #11278

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading