From 814fc4dd6a20d843f6b5a45a0cd0ce51c6fd5ba2 Mon Sep 17 00:00:00 2001 From: John Koster Date: Sat, 2 Mar 2024 16:24:40 -0600 Subject: [PATCH 1/6] Removes fluent getter/setter and caches results for origin and hasOrigin --- src/Data/HasOrigin.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index 186299cfad..e2cbf854b5 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -10,6 +10,7 @@ trait HasOrigin * @var string */ protected $origin; + protected $cachedHasOrigin = false; public function keys() { @@ -58,18 +59,18 @@ public function value($key) public function origin($origin = null) { - return $this->fluentlyGetOrSet('origin') - ->getter(function ($origin) { - return $origin - ? Blink::once($this->getOriginBlinkKey(), fn () => $this->getOriginByString($origin)) - : null; - }) - ->setter(function ($origin) { - Blink::forget($this->getOriginBlinkKey()); - - return is_object($origin) ? $this->getOriginIdFromObject($origin) : $origin; - }) - ->args(func_get_args()); + if (func_num_args() === 0) { + return $this->origin + ? Blink::once($this->getOriginBlinkKey(), fn () => $this->getOriginByString($this->origin)) + : null; + } + + Blink::forget($this->getOriginBlinkKey()); + + $this->origin = is_object($origin) ? $this->getOriginIdFromObject($origin) : $origin; + $this->cachedHasOrigin = $this->origin != null; + + return $this; } abstract public function getOriginByString($origin); @@ -86,7 +87,11 @@ protected function getOriginIdFromObject($origin) public function hasOrigin() { - return $this->origin() !== null; + if (! $this->cachedHasOrigin && $this->origin) { + $this->cachedHasOrigin = true; + } + + return $this->cachedHasOrigin; } public function isRoot() From a3c32c1e9483b47ba3fc77166dca73f4a978eb76 Mon Sep 17 00:00:00 2001 From: John Koster Date: Tue, 12 Mar 2024 19:26:09 -0500 Subject: [PATCH 2/6] Refactor hasOrigin() cached call --- src/Data/HasOrigin.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index e2cbf854b5..f1cf7c07c1 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -10,7 +10,6 @@ trait HasOrigin * @var string */ protected $origin; - protected $cachedHasOrigin = false; public function keys() { @@ -68,7 +67,6 @@ public function origin($origin = null) Blink::forget($this->getOriginBlinkKey()); $this->origin = is_object($origin) ? $this->getOriginIdFromObject($origin) : $origin; - $this->cachedHasOrigin = $this->origin != null; return $this; } @@ -87,11 +85,7 @@ protected function getOriginIdFromObject($origin) public function hasOrigin() { - if (! $this->cachedHasOrigin && $this->origin) { - $this->cachedHasOrigin = true; - } - - return $this->cachedHasOrigin; + return $this->origin != null; } public function isRoot() From d5ced64793af61b4c049a1efe4e7fdc88810fb3b Mon Sep 17 00:00:00 2001 From: John Koster Date: Tue, 12 Mar 2024 19:36:09 -0500 Subject: [PATCH 3/6] Update HasOrigin.php --- src/Data/HasOrigin.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index 4510233dde..ebdaf9437c 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -64,10 +64,6 @@ public function value($key) public function origin($origin = null) { if (func_num_args() === 0) { - if (! $origin) { - return null; - } - if ($found = Blink::get($this->getOriginBlinkKey())) { return $found; } From ad4285139ae6661b8bad62d98a8e78f03b78b1b8 Mon Sep 17 00:00:00 2001 From: John Koster Date: Tue, 12 Mar 2024 19:51:12 -0500 Subject: [PATCH 4/6] Revert "Update HasOrigin.php" This reverts commit d5ced64793af61b4c049a1efe4e7fdc88810fb3b. --- src/Data/HasOrigin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index ebdaf9437c..4510233dde 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -64,6 +64,10 @@ public function value($key) public function origin($origin = null) { if (func_num_args() === 0) { + if (! $origin) { + return null; + } + if ($found = Blink::get($this->getOriginBlinkKey())) { return $found; } From 6a02ad4ba3d288554f9fd5ac96ebe127345f1915 Mon Sep 17 00:00:00 2001 From: John Koster Date: Tue, 12 Mar 2024 20:05:34 -0500 Subject: [PATCH 5/6] =?UTF-8?q?"$this->"=20was=20important=20=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data/HasOrigin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index 4510233dde..33c0de88c5 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -64,7 +64,7 @@ public function value($key) public function origin($origin = null) { if (func_num_args() === 0) { - if (! $origin) { + if (! $this->origin) { return null; } @@ -72,7 +72,7 @@ public function origin($origin = null) return $found; } - return tap($this->getOriginByString($origin), function ($found) { + return tap($this->getOriginByString($this->origin), function ($found) { Blink::put($this->getOriginBlinkKey(), $found); }); } @@ -98,7 +98,7 @@ protected function getOriginIdFromObject($origin) public function hasOrigin() { - return $this->origin != null; + return $this->origin !== null; } public function isRoot() From cc1f7224408f6ced8da05224cdc54a938d6eded6 Mon Sep 17 00:00:00 2001 From: John Koster Date: Sun, 24 Mar 2024 12:28:04 -0500 Subject: [PATCH 6/6] Still call method in the event we haven't actually resolved the origin yet --- src/Data/HasOrigin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/HasOrigin.php b/src/Data/HasOrigin.php index 33c0de88c5..fe045594ee 100644 --- a/src/Data/HasOrigin.php +++ b/src/Data/HasOrigin.php @@ -98,7 +98,7 @@ protected function getOriginIdFromObject($origin) public function hasOrigin() { - return $this->origin !== null; + return $this->origin() !== null; } public function isRoot()