From 2ef3f575c39ac2c9296a7f8399f488c100944ebd Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 15 Jan 2026 22:43:00 +0100 Subject: [PATCH] PageTemplate/Misc * fetch user vars on __wakeup / __construct so the queries get picked up by the DB profiler * unset temporary vars before serialization * reduce redundancy --- includes/components/pagetemplate.class.php | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/includes/components/pagetemplate.class.php b/includes/components/pagetemplate.class.php index eb2e35c9..c13d0eeb 100644 --- a/includes/components/pagetemplate.class.php +++ b/includes/components/pagetemplate.class.php @@ -46,12 +46,10 @@ class PageTemplate public function __construct(private string $template, private ?\Aowow\TemplateResponse $context = null) { - $this->locale = Lang::getLocale(); - $this->gStaticUrl = Cfg::get('STATIC_URL'); - $this->gHost = Cfg::get('HOST_URL'); - $this->hasAnalytics = !!Cfg::get('GTAG_MEASUREMENT_ID'); - $this->gServerTime = sprintf("new Date('%s')", date(Util::$dateFormatInternal)); - $this->user = User::class; + $this->locale = Lang::getLocale(); + $this->user = User::class; + + self::__wakeup(); // init non-cached properties; } public function addDataLoader(string ...$dataFile) : void @@ -486,9 +484,6 @@ class PageTemplate // js + css $this->prepareScripts(); - $this->gUser = Util::toJSON(User::getUserGlobal()); - $this->gFavorites = Util::toJSON(User::getFavorites()); - // db profiling if (Cfg::get('DEBUG') >= LOG_LEVEL_INFO && User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)) $this->dbProfiles = \Aowow\DB::getProfiles(); @@ -510,6 +505,15 @@ class PageTemplate $this->context = null; // unlink from TemplateResponse $this->pageData = []; // clear modified data + unset( // must be recreated on __wakeup + $this->gStaticUrl, + $this->gHost, + $this->hasAnalytics, + $this->gServerTime, + $this->gUser, + $this->gFavorites + ); + if ($this->lvTabs) // do not store lvErrors in cache foreach ($this->lvTabs->iterate() as $lv) if ($lv instanceof \Aowow\Listview) @@ -531,6 +535,8 @@ class PageTemplate $this->gHost = Cfg::get('HOST_URL'); $this->hasAnalytics = !!Cfg::get('GTAG_MEASUREMENT_ID'); $this->gServerTime = sprintf("new Date('%s')", date(Util::$dateFormatInternal)); + $this->gUser = Util::toJSON(User::getUserGlobal()); + $this->gFavorites = Util::toJSON(User::getFavorites()); } public function __set(string $var, mixed $value) : void