diff --git a/src/Console/Commands/StaticWarm.php b/src/Console/Commands/StaticWarm.php index d8b3867aa26..e538f6cf013 100644 --- a/src/Console/Commands/StaticWarm.php +++ b/src/Console/Commands/StaticWarm.php @@ -124,7 +124,7 @@ private function warm(): void private function warmPaginatedPages(string $url, int $currentPage, int $totalPages, string $pageName): void { $urls = collect(range($currentPage, $totalPages))->map(function ($page) use ($url, $pageName) { - $url = "{$url}?{$pageName}={$page}"; + $url = $url.(str_contains($url, '?') ? '&' : '?')."{$pageName}={$page}"; if (config('statamic.static_caching.background_recache', false)) { $url = RecacheToken::addToUrl($url); @@ -172,12 +172,14 @@ private function clientConfig(): array public function outputSuccessLine(Response $response, $index): void { - $this->components->twoColumnDetail($this->getRelativeUri($this->uris()->get($index)), '✓ Cached'); + $url = $this->uris()->get($index); - if ($response->hasHeader('X-Statamic-Pagination')) { + $this->components->twoColumnDetail($this->getRelativeUri($url), '✓ Cached'); + + if ($this->shouldWarmPaginatedPages($response, $url)) { [$currentPage, $totalPages, $pageName] = $this->paginationHeader($response); - $this->warmPaginatedPages($this->uris()->get($index), $currentPage, $totalPages, $pageName); + $this->warmPaginatedPages($url, $currentPage, $totalPages, $pageName); } } @@ -276,6 +278,17 @@ private function shouldExclude($uri): bool return collect($exclusions)->contains(fn ($excluded) => $this->uriMatches($uri, $excluded)); } + private function shouldWarmPaginatedPages(Response $response, string $url): bool + { + if (! $response->hasHeader('X-Statamic-Pagination')) { + return false; + } + + [$currentPage, $totalPages, $pageName] = $this->paginationHeader($response); + + return ! str_contains(parse_url($url, PHP_URL_QUERY) ?? '', "{$pageName}="); + } + private function uriMatches($uri, $pattern): bool { $uri = URL::makeRelative($uri);