Skip to content

Commit

Permalink
[5.x] Simplify collection and cache getComputedCallbacks on Entry i…
Browse files Browse the repository at this point in the history
…nstances (#9642)

Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
JohnathonKoster and jasonvarga authored Apr 1, 2024
1 parent 6b626b8 commit ba96445
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Entry implements Arrayable, ArrayAccess, Augmentable, ContainsQueryableVal
protected $withEvents = true;
protected $template;
protected $layout;
private $computedCallbackCache;
private $siteCache;

public function __construct()
Expand Down Expand Up @@ -128,6 +129,7 @@ public function collection($collection = null)
}) : null;
}

$this->computedCallbackCache = null;
$this->collection = $collection instanceof \Statamic\Contracts\Entries\Collection ? $collection->handle() : $collection;

return $this;
Expand Down Expand Up @@ -1019,7 +1021,11 @@ public function getCpSearchResultBadge(): string

protected function getComputedCallbacks()
{
return Facades\Collection::getComputedCallbacks($this->collection);
if ($this->computedCallbackCache) {
return $this->computedCallbackCache;
}

return $this->computedCallbackCache = Facades\Collection::getComputedCallbacks($this->collection);
}

public function __sleep()
Expand All @@ -1029,6 +1035,6 @@ public function __sleep()
$this->slug = $slug($this);
}

return array_keys(get_object_vars($this));
return array_keys(Arr::except(get_object_vars($this), ['computedCallbackCache']));
}
}

0 comments on commit ba96445

Please sign in to comment.