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] Cache Augmentation Keys on Instance #9581

Merged
merged 9 commits into from
Mar 12, 2024
Merged
8 changes: 7 additions & 1 deletion src/Assets/AugmentedAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

class AugmentedAsset extends AbstractAugmented
{
protected $cachedKeys = null;

public function keys()
{
if ($this->cachedKeys) {
return $this->cachedKeys;
}

$keys = $this->data->data()->keys()
->merge($this->data->supplements()->keys())
->merge([
Expand Down Expand Up @@ -65,7 +71,7 @@ public function keys()
]);
}

return $keys->merge($this->blueprintFields()->keys())->unique()->all();
return $this->cachedKeys = $keys->merge($this->blueprintFields()->keys())->unique()->all();
}

protected function isAsset()
Expand Down
8 changes: 7 additions & 1 deletion src/Auth/AugmentedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@

class AugmentedUser extends AbstractAugmented
{
protected $cachedKeys = null;

public function keys()
{
return $this->data->data()->keys()
if ($this->cachedKeys) {
return $this->cachedKeys;
}

return $this->cachedKeys = $this->data->data()->keys()
->merge(collect($this->data->supplements() ?? [])->keys())
->merge($this->commonKeys())
->merge($this->roleHandles())
Expand Down
8 changes: 7 additions & 1 deletion src/Data/HasOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ trait HasOrigin
*/
protected $origin;

protected $cachedKeys = null;

public function keys()
{
if ($this->cachedKeys) {
return $this->cachedKeys;
}

$originFallbackKeys = method_exists($this, 'getOriginFallbackValues') ? $this->getOriginFallbackValues()->keys() : collect();

$originKeys = $this->hasOrigin() ? $this->origin()->keys() : collect();

$computedKeys = method_exists($this, 'computedKeys') ? $this->computedKeys() : [];

return collect()
return $this->cachedKeys = collect()
->merge($originFallbackKeys)
->merge($originKeys)
->merge($this->data->keys())
Expand Down
8 changes: 7 additions & 1 deletion src/Entries/AugmentedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

class AugmentedEntry extends AbstractAugmented
{
protected $keysCache = null;

public function keys()
{
return $this->data->keys()
if ($this->keysCache) {
return $this->keysCache;
}

return $this->keysCache = $this->data->keys()
->merge($this->data->supplements()->keys())
->merge($this->commonKeys())
->merge($this->blueprintFields()->keys())
Expand Down
8 changes: 7 additions & 1 deletion src/Globals/AugmentedVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

class AugmentedVariables extends AbstractAugmented
{
protected $cachedKeys = null;

public function keys()
{
return $this->data->values()->keys()->all();
if ($this->cachedKeys) {
return $this->cachedKeys;
}

return $this->cachedKeys = $this->data->values()->keys()->all();
}

public function site()
Expand Down
8 changes: 7 additions & 1 deletion src/Structures/AugmentedPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public function __construct($page)
}
}

protected $cachedKeys = null;

public function keys()
{
if ($this->cachedKeys) {
return $this->cachedKeys;
}

$keys = collect($this->hasEntry
? parent::keys()
: ['title', 'url', 'uri', 'permalink', 'id']);
Expand All @@ -35,7 +41,7 @@ public function keys()

$keys = Statamic::isApiRoute() ? $this->apiKeys($keys) : $keys;

return $keys->unique()->sort()->values()->all();
return $this->cachedKeys = $keys->unique()->sort()->values()->all();
}

private function apiKeys($keys)
Expand Down
8 changes: 7 additions & 1 deletion src/Taxonomies/AugmentedTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

class AugmentedTerm extends AbstractAugmented
{
protected $cachedKeys = null;

public function keys()
{
return $this->data->values()->keys()
if ($this->cachedKeys) {
return $this->cachedKeys;
}

return $this->cachedKeys = $this->data->values()->keys()
->merge($this->data->supplements()->keys())
->merge($this->commonKeys())
->merge($this->blueprintFields()->keys())
Expand Down
Loading