diff options
| author | czaks <marcin@6irc.net> | 2015-04-05 16:38:16 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2015-04-05 16:38:16 +0200 |
| commit | 71ef3430fc3385f343b9e2c3eb4d05eaeca8607a (patch) | |
| tree | d2e675d26b377d6a7b603b4baddab5e7d7f57313 /inc | |
| parent | 34eeaccea9f3809fdfa465e9910c8fa84f836011 (diff) | |
optimization: get rid of one more sql query related to installed themes
Diffstat (limited to 'inc')
| -rwxr-xr-x | inc/functions.php | 23 |
1 files 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; } |
