From bafd057f8ce0faefc1509ed544a2baf57ac0feac Mon Sep 17 00:00:00 2001 From: Vojta Svoboda Date: Wed, 25 Sep 2019 20:26:55 +0200 Subject: [PATCH] Optimize theme recognition (#3220) Credit to @vojtasvoboda. Will avoid asking the database for the currently active theme if there is only one theme present and its code matches the code set in cms.activeTheme --- modules/cms/classes/Theme.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index 0086ecc99..50d62ae02 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -150,8 +150,12 @@ class Theme public static function getActiveThemeCode() { $activeTheme = Config::get('cms.activeTheme'); + $themes = static::all(); + $havingMoreThemes = count($themes) > 1; + $themeHasChanged = !empty($themes[0]) && $themes[0]->dirName !== $activeTheme; + $checkDatabase = $havingMoreThemes || $themeHasChanged; - if (App::hasDatabase()) { + if ($checkDatabase && App::hasDatabase()) { try { try { $dbResult = Cache::remember(self::ACTIVE_KEY, 1440, function () {