From 1c63e7acda74d0010484b17515610c5528ecaef7 Mon Sep 17 00:00:00 2001 From: John Koster Date: Sun, 3 Mar 2024 11:13:23 -0600 Subject: [PATCH 1/2] Cache urls on Page instances --- src/Structures/Page.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Structures/Page.php b/src/Structures/Page.php index 7455bd64d38..3a73dd67bbf 100644 --- a/src/Structures/Page.php +++ b/src/Structures/Page.php @@ -39,6 +39,8 @@ class Page implements Arrayable, ArrayAccess, Augmentable, Entry, JsonSerializab protected $title; protected $depth; protected $data = []; + protected $absoluteUrl; + protected $absoluteUrlWithoutRedirect; public function __construct() { @@ -210,20 +212,28 @@ public function uri() public function absoluteUrl() { + if ($this->absoluteUrl !== null) { + return $this->absoluteUrl; + } + if ($this->url) { - return URL::makeAbsolute($this->url); + return $this->absoluteUrl = URL::makeAbsolute($this->url); } - return optional($this->entry())->absoluteUrl(); + return $this->absoluteUrl = optional($this->entry())->absoluteUrl(); } public function absoluteUrlWithoutRedirect() { + if ($this->absoluteUrlWithoutRedirect !== null) { + return $this->absoluteUrlWithoutRedirect; + } + if ($this->url) { - return $this->absoluteUrl(); + return $this->absoluteUrlWithoutRedirect = $this->absoluteUrl(); } - return optional($this->entry())->absoluteUrlWithoutRedirect(); + return $this->absoluteUrlWithoutRedirect = optional($this->entry())->absoluteUrlWithoutRedirect(); } public function isRoot() From d50f09f914f55c6a115de70520fdddc7acfd8b44 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 12 Mar 2024 10:56:19 -0400 Subject: [PATCH 2/2] visibility --- src/Structures/Page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Structures/Page.php b/src/Structures/Page.php index 3a73dd67bbf..70be615f9c4 100644 --- a/src/Structures/Page.php +++ b/src/Structures/Page.php @@ -39,8 +39,8 @@ class Page implements Arrayable, ArrayAccess, Augmentable, Entry, JsonSerializab protected $title; protected $depth; protected $data = []; - protected $absoluteUrl; - protected $absoluteUrlWithoutRedirect; + private $absoluteUrl; + private $absoluteUrlWithoutRedirect; public function __construct() {