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
This commit is contained in:
Vojta Svoboda 2019-09-25 20:26:55 +02:00 committed by Luke Towers
parent 33d149fe1a
commit bafd057f8c
1 changed files with 5 additions and 1 deletions

View File

@ -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 () {