Skip to content

[6.x] Don't re-paginate already-paginated URLs in static:warm - #15282

Merged
duncanmcclean merged 1 commit into
statamic:6.xfrom
steveparks:patch-5
Nov 17, 2026
Merged

duncanmcclean merged 1 commit into
statamic:6.xfrom
steveparks:patch-5

Conversation

@steveparks

@steveparks steveparks commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

StaticWarm follows pagination on any URL whose response carries an X-Statamic-Pagination header, including a URL that is itself already a page. StaticWarmJob guards against this; the command didn't.

This reaches real sites because additionalUris() is a public extension point (StaticWarm::hook('additional', …)), and feeding paginated URLs through it is a reasonable thing to do. Eg it is how a site re-warms ?page=N pages that fell out of the cache while their index page stayed in it, which the compiled URI list cannot reach on its own because pagination is only discoverable from a response header.

Such a URL answers with a pagination header of its own, so the command goes on to request ?page=3&page=4, ?page=3&page=5 and so on. They render, but they are not the canonical URL of anything, so it's wasted work. (Before #15852 they were ?page=3?page=4; the separator is now right, but the extra requests remain.)

The fix

Mirror StaticWarmJob: a private shouldWarmPaginatedPages() that checks for the header and skips URLs that already carry the page parameter, called from outputSuccessLine().

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}=");
}

Test

it_doesnt_paginate_a_url_that_already_has_the_page_parameter: an already-paginated URL (/zebra?page=3) comes in through the additional hook with a pagination header of current: 3, total: 4, and only page=3 is requested. Without the guard it also requests page=3&page=4.

@steveparks

Copy link
Copy Markdown
Contributor Author

One other point on this....

The check above (copied from the job) matches on a substring, and $pageName is configurable: page_name on the paginating tag, defaulting to page (Tags/Concerns/GetsQueryResults.php).

So a query parameter whose name ends with the page name collides. With the default page, a URL carrying
?news_page=3 reads as already-paginated and its pagination is silently skipped. news_page is what the conventional workaround for two paginated collections on one page produces, so could happen.

Anchoring on the parameter boundary would avoid it:

return ! Str::startsWith($query, "{$pageName}=")
    && ! Str::contains($query, "&{$pageName}=");

I didn't include this in the PR as it's a bigger decision affecting both StaticWarm (after this PR) and StaticWarmJob (as it already is). Maybe this strengthens the case for the trait alternative approach?

@steveparks

Copy link
Copy Markdown
Contributor Author

Dammit, looks like I have whitespace issues again. Sorry.
I'll really have to figure out how to contribute upstream PRs from my dev environment rather than trying to replicate through the Github UI!

@jasonvarga

Copy link
Copy Markdown
Member

Do you see this above the comment box?

CleanShot 2026-08-26 at 13 20 02

What happens if you click Lint code style issues – are you able to see the output?

@steveparks

Copy link
Copy Markdown
Contributor Author

Yes, it shows me the output if I click that — which is where I saw what (I thought) said it was whitespace issues.

I'm obviously not doing things correctly in the GH editor in the UI.

@jasonvarga

Copy link
Copy Markdown
Member

No worries. It's not really clear from that output since it doesn't actually show you the whitespace.
In the GitHub UI you could have seen it though. There was just some trailing whitespace after the brace.

I've fixed it for you: f3b438d

@steveparks

Copy link
Copy Markdown
Contributor Author

Quick update now that 6.42 is out: #15852 reworked pagination warming in StaticWarm, so this PR no longer applies as written.

The new code does include the separator half of it: paginatedUrls() now joins with '&' when the URL already has a query string, so the malformed ?page=3?page=4 URLs are gone. 🎉

The re-pagination itself is still there, though.

outputSuccessLine() records every response that has a pagination header, including URLs that are already a page. So a ?page=3 coming in through the additional hook produces ?page=3&page=4, ?page=3&page=5 … ?page=3&page=N.

It's much less harmful than before. Laravel normalises the repeated parameter to ?page=N before the cacher keys it, so nothing gets cached under a junk URL. And the new getUrl() comparison drops the ?page=3&page=3 duplicate. But each already-paginated URL still re-requests all the pages after it, so the extra requests grow with the square of the pagination set. When those siblings aren't cached yet, several of those requests can also render the same page at once.

StaticWarmJob still has its shouldWarmPaginatedPages() guard, so the queued path doesn't do this. The command just doesn't have an equivalent.

In the new structure the fix is small: skip recording the URL when it already carries the page parameter.

 if ($response->hasHeader('X-Statamic-Pagination')) {
     [$currentPage, $totalPages, $pageName] = $this->paginationHeader($response);
     $url = $this->uris()->get($index);

     if (! $this->isAlreadyPaginated($url, $pageName)) {
         $this->paginated[] = [$url, $currentPage, $totalPages, $pageName];
     }
 }

So you prefer us to update this PR, or to close it if you'd rather treat the leftover requests as acceptable now that they at least resolve to the right URLs? Whichever you prefer.

@duncanmcclean

Copy link
Copy Markdown
Member

Thanks for comparing this against the new code.

Let's update this PR rather than close it. The extra requests are wasted work, and the command should behave the same as the queued job.

Could you rebase onto 6.x and add the guard to outputSuccessLine()? I'd mirror StaticWarmJob here: a private shouldWarmPaginatedPages() that checks for the header and skips URLs that already have the page parameter. A test where an already-paginated URL comes in through the additional hook would be great too.

…c:warm

Mirrors StaticWarmJob::shouldWarmPaginatedPages(): a URL that already has
the page query parameter (e.g. one supplied through the `additional` hook)
is warmed as-is, rather than having further pages appended to it.
@steveparks steveparks changed the title [6.x] Fix: StaticWarm re-paginates already-paginated URLs, producing ?page=3?page=4 [6.x] Don't re-paginate already-paginated URLs in static:warm Nov 16, 2026
@steveparks

Copy link
Copy Markdown
Contributor Author

Rebased onto 6.x. #15852 had already taken care of the & joining, so this is now just the guard: a private shouldWarmPaginatedPages() in StaticWarm mirroring StaticWarmJob, plus a test where an already-paginated URL comes in through the additional hook. I've updated the title and description to match.

Usual caveat applies that I'm not an experienced contributor, so apologies if I am not submitting this correctly. I didn't use the Github UI this time, so hope to have avoided the whitespace issues!

@duncanmcclean duncanmcclean left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@duncanmcclean
duncanmcclean merged commit 25e8bfc into statamic:6.x Nov 17, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants