[6.x] Warm paginated pages with static:warm command#9493
Conversation
static:warm command
By default, we'll have the `page` query parameter in here so pagination works. However, if you change the pagination param name or have some other query parameter you want to whitelist, then that setting lets you do that.
# Conflicts: # src/Console/Commands/StaticWarm.php
static:warm commandstatic:warm command
# Conflicts: # src/Console/Commands/StaticWarm.php # src/Console/Commands/StaticWarmJob.php # src/StaticCaching/Middleware/Cache.php # tests/Console/Commands/StaticWarmJobTest.php # tests/StaticCaching/CacherTest.php
|
@duncanmcclean Can we add query string sorting as well? Take a look at the original code example i posted in the private channel. This version takes a few more options into account:
public function getUrl(Request $request)
{
$url = $request->getUri();
if ($this->config('ignore_query_strings')) {
$url = explode('?', $url)[0];
}
$parts = parse_url($url);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
if ($this->config('sort_query_strings')) {
$query = Arr::sort($query);
}
if ($allowedQueryStrings = $this->config('allowed_query_strings')) {
$query = array_intersect_key($query, array_flip($allowedQueryStrings));
}
if ($disallowedQueryStrings = $this->config('disallowed_query_strings')) {
$disallowedQueryStrings = array_flip($disallowedQueryStrings);
$query = array_diff_key($query, $disallowedQueryStrings);
}
$url = $parts['scheme'] . '://' . $parts['host'] . '?'. http_build_query($query);
}
return $url;
} |
|
@sylvesterdamgaard I've split out the "allowed query parameters" part into a separate PR, where I've also implemented the sorting/disallowed options: #10701 |
jasonvarga
left a comment
There was a problem hiding this comment.
Gonna mark this as a draft. My previous review somehow got marked as resolved but I think it's still valid.
This unfortunately only works the first time.
Run php please static:warm, you'll see the paginated pages in the output.
Run it again, they won't be there.
This might not be an issue after #9396
# Conflicts: # config/static_caching.php # src/StaticCaching/Cachers/AbstractCacher.php # src/StaticCaching/StaticCacheManager.php # tests/StaticCaching/CacherTest.php
This reverts commit 9991ea4.
|
Hi! |
|
Sorry, we don't have an ETA for reviewing/merging this pull request. We'll get to it when we can. In the meantime, you can pull this PR into your project with a composer patch. |
|
This needs to target master and be updated appropriately since #9396 has merged. |
static:warm commandstatic:warm command
This pull request implements warming of paginated pages into the
static:warmcommand. This will be especially useful for larger sites which have lots of pagination pages since right now, only the first page is warmed.How it works
Under the hood, Statamic's
Cachemiddleware checks if there's a paginator instance being "blinked". If there is, a header is added to the response containing the URL of the next paginated page.This header then gets picked up by the
static:warmcommand and triggers the paginated page to be warmed, which happens in a loop until there's no more paginated pages to warm.The implementation is inspired by statamic/ssg#140.
Warning
Due to the nature of the setting, this feature will only work when
'ignore_query_strings' => false.It will also only pick up paginated pages when the first page isn't already cached (unless you're using the background re-caching feature).