Skip to content

Commit

Permalink
[5.x] Reduce the number of times the fieldsCache is reset (#9585)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
JohnathonKoster and jasonvarga authored Apr 16, 2024
1 parent 2122b85 commit f8f0226
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Fields/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit f8f0226

Please sign in to comment.