Skip to content

Commit

Permalink
[4.x] Change nocache performance optimizations to be opt-in (#9124)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Dec 5, 2023
1 parent 24ebdf6 commit 74aadb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/StaticCaching/NoCache/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public function index()
{
if ($this->params->has('select')) {
$fields = $this->params->explode('select');
} elseif (config('statamic.antlers.version') === 'runtime') {
$fields = Antlers::identifiers($this->content);

if (in_array('@auto', $fields)) {
$identifiers = Antlers::identifiers($this->content);
$fields = array_merge(array_diff($fields, ['@auto']), $identifiers);
}
}

return $this
Expand Down
11 changes: 7 additions & 4 deletions tests/StaticCaching/NocacheTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ public function it_can_keep_nested_nocache_tags_dynamic_inside_cache_tags()
/** @test */
public function it_only_adds_appropriate_fields_of_context_to_session()
{
// We will not add `baz` to the session because it is not used in the template.
// We will not add `nope` to the session because it is not in the context.
$expectedFields = ['foo', 'bar'];
$template = '{{ nocache }}{{ foo }}{{ bar }}{{ nope }}{{ /nocache }}';
$expectedFields = [
'foo', // By adding @auto it will be picked up from the template.
'baz', // Explicitly selected
// 'bar' // Not explicitly selected
// 'nope' // Not in the context
];
$template = '{{ nocache select="@auto|baz" }}{{ foo }}{{ nope }}{{ /nocache }}';
$context = [
'foo' => 'alfa',
'bar' => 'bravo',
Expand Down

0 comments on commit 74aadb1

Please sign in to comment.