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
This commit is contained in:
Sarjuuk 2026-01-15 22:43:00 +01:00
parent 59506dda11
commit 2ef3f575c3

View file

@ -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