Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Reduce the number of times the fieldsCache is reset #9585

Merged
merged 9 commits into from
Apr 16, 2024
Merged
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
Loading