From 74aadb1ccee65646b20e155be7f39c7bb696aad8 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 5 Dec 2023 12:17:26 -0500 Subject: [PATCH] [4.x] Change nocache performance optimizations to be opt-in (#9124) --- src/StaticCaching/NoCache/Tags.php | 7 +++++-- tests/StaticCaching/NocacheTagsTest.php | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/StaticCaching/NoCache/Tags.php b/src/StaticCaching/NoCache/Tags.php index 90c0a8c721..60a08a7387 100644 --- a/src/StaticCaching/NoCache/Tags.php +++ b/src/StaticCaching/NoCache/Tags.php @@ -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 diff --git a/tests/StaticCaching/NocacheTagsTest.php b/tests/StaticCaching/NocacheTagsTest.php index f33f0314e8..5929cb2882 100644 --- a/tests/StaticCaching/NocacheTagsTest.php +++ b/tests/StaticCaching/NocacheTagsTest.php @@ -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',