From 80e584f46b0e856163edf5456d102d3300f32712 Mon Sep 17 00:00:00 2001 From: Tin <31577031+modrictin@users.noreply.github.com> Date: Thu, 16 May 2024 11:54:44 +0200 Subject: [PATCH 1/2] [5.x] Don't call ->in() twice while hydrating globals The `existsIn()` method calls `->in()` inside. The `in()` method is resource consuming when someone has a lot of sites. This reduce the loading time of this function up to 50%. --- src/View/Cascade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/View/Cascade.php b/src/View/Cascade.php index 326d8b1bd5..b207b9ce7d 100644 --- a/src/View/Cascade.php +++ b/src/View/Cascade.php @@ -138,12 +138,12 @@ protected function hydrateSegments() protected function hydrateGlobals() { foreach (GlobalSet::all() as $global) { - if (! $global->existsIn($this->site->handle())) { + $global = $global?->in($this->site->handle()); + + if (! $global) { continue; } - $global = $global->in($this->site->handle()); - $this->set($global->handle(), $global); } From b91dff48baf8e87baf857659bd975d9580026ba3 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 16 May 2024 10:34:03 -0400 Subject: [PATCH 2/2] nitpick --- src/View/Cascade.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/View/Cascade.php b/src/View/Cascade.php index b207b9ce7d..85758fc158 100644 --- a/src/View/Cascade.php +++ b/src/View/Cascade.php @@ -138,13 +138,9 @@ protected function hydrateSegments() protected function hydrateGlobals() { foreach (GlobalSet::all() as $global) { - $global = $global?->in($this->site->handle()); - - if (! $global) { - continue; + if ($global = $global->in($this->site->handle())) { + $this->set($global->handle(), $global); } - - $this->set($global->handle(), $global); } if ($mainGlobal = $this->get('global')) {