From f8f022672414ab18859f315aa7d9365c648acfcc Mon Sep 17 00:00:00 2001 From: John Koster Date: Tue, 16 Apr 2024 09:01:20 -0500 Subject: [PATCH] [5.x] Reduce the number of times the `fieldsCache` is reset (#9585) Co-authored-by: Jason Varga --- src/Fields/Blueprint.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Fields/Blueprint.php b/src/Fields/Blueprint.php index 2927f3fff7..2e77a4ec8e 100644 --- a/src/Fields/Blueprint.php +++ b/src/Fields/Blueprint.php @@ -42,6 +42,8 @@ class Blueprint implements Arrayable, ArrayAccess, Augmentable, QueryableValue protected $ensuredFields = []; protected $afterSaveCallbacks = []; protected $withEvents = true; + private $lastBlueprintHandle = null; + private ?Columns $columns = null; public function setHandle(string $handle) @@ -635,6 +637,16 @@ public function validateUniqueHandles() protected function resetFieldsCache() { + if ($this->parent) { + $blueprint = (fn () => property_exists($this, 'blueprint') ? $this->blueprint : null)->call($this->parent); + + if ($blueprint && $blueprint === $this->lastBlueprintHandle) { + return $this; + } + + $this->lastBlueprintHandle = $blueprint; + } + $this->fieldsCache = null; Blink::forget($this->contentsBlinkKey());