Repository navigation
[6.x] Don't re-paginate already-paginated URLs in static:warm - #15282
Conversation
|
One other point on this.... The check above (copied from the job) matches on a substring, and So a query parameter whose name ends with the page name collides. With the default 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 |
|
Dammit, looks like I have whitespace issues again. Sorry. |
|
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. |
|
No worries. It's not really clear from that output since it doesn't actually show you the whitespace. I've fixed it for you: f3b438d |
|
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. 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. |
|
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 |
…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.
StaticWarm re-paginates already-paginated URLs, producing ?page=3?page=4static:warm
|
Rebased onto 6.x. #15852 had already taken care of the 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! |

StaticWarmfollows pagination on any URL whose response carries anX-Statamic-Paginationheader, including a URL that is itself already a page.StaticWarmJobguards 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=Npages 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=5and 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 privateshouldWarmPaginatedPages()that checks for the header and skips URLs that already carry the page parameter, called fromoutputSuccessLine().Test
it_doesnt_paginate_a_url_that_already_has_the_page_parameter: an already-paginated URL (/zebra?page=3) comes in through theadditionalhook with a pagination header ofcurrent: 3, total: 4, and onlypage=3is requested. Without the guard it also requestspage=3&page=4.