From 71ef3430fc3385f343b9e2c3eb4d05eaeca8607a Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:38:16 +0200 Subject: [PATCH] optimization: get rid of one more sql query related to installed themes --- inc/functions.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index b1b1b042..8a98659b 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -352,9 +352,22 @@ function rebuildThemes($action, $boardname = false) { $_board = $board; // List themes - $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error()); + if ($themes = Cache::get("themes")) { + // OK, we already have themes loaded + } + else { + $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error()); + + $themes = array(); + + while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { + $themes[] = $theme; + } - while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { + Cache::set("themes", $themes); + } + + foreach ($themes as $theme) { // Restore them $config = $_config; $board = $_board; @@ -415,6 +428,10 @@ function rebuildTheme($theme, $action, $board = false) { function themeSettings($theme) { + if ($settings = Cache::get("theme_settings_".$theme)) { + return $settings; + } + $query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL"); $query->bindValue(':theme', $theme); $query->execute() or error(db_error($query)); @@ -424,6 +441,8 @@ function themeSettings($theme) { $settings[$s['name']] = $s['value']; } + Cache::set("theme_settings_".$theme, $settings); + return $settings; }