From b5020645beb05485cc365a7cf01e4acc056f1cd2 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 29 Oct 2014 15:02:55 +0000 Subject: [PATCH] Remove Settings::update method It was too slow --- .../Mibew/Controller/CronController.php | 1 - .../Controller/Settings/CommonController.php | 1 - .../Settings/FeaturesController.php | 2 -- .../Settings/PerformanceController.php | 1 - src/mibew/libs/classes/Mibew/Settings.php | 28 ++++++++----------- .../libs/classes/Mibew/Style/ChatStyle.php | 1 - .../classes/Mibew/Style/InvitationStyle.php | 1 - .../libs/classes/Mibew/Style/PageStyle.php | 1 - 8 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Controller/CronController.php b/src/mibew/libs/classes/Mibew/Controller/CronController.php index 70b6ccc3..950829cb 100644 --- a/src/mibew/libs/classes/Mibew/Controller/CronController.php +++ b/src/mibew/libs/classes/Mibew/Controller/CronController.php @@ -66,7 +66,6 @@ class CronController extends AbstractController // Update time of last cron run Settings::set('_last_cron_run', time()); - Settings::update(); if (!$quiet) { // TODO: May be localize it diff --git a/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php b/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php index b55c0bff..59107e5b 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php @@ -210,7 +210,6 @@ class CommonController extends AbstractController foreach ($params as $key => $value) { Settings::set($key, $value); } - Settings::update(); // Update styles params ChatStyle::setDefaultStyle($chat_style); diff --git a/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php b/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php index 2e05c6d6..6786a3ab 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Settings/FeaturesController.php @@ -45,7 +45,6 @@ class FeaturesController extends AbstractController if (Settings::get('featuresversion') != FEATURES_VERSION) { Settings::set('featuresversion', FEATURES_VERSION); - Settings::update(); } // Load all needed options and fill form with them. @@ -84,7 +83,6 @@ class FeaturesController extends AbstractController $value = $request->request->get($opt) == 'on' ? '1' : '0'; Settings::set($opt, $value); } - Settings::update(); // Redirect the current operator to the same page using GET method. $redirect_to = $this->generateUrl( diff --git a/src/mibew/libs/classes/Mibew/Controller/Settings/PerformanceController.php b/src/mibew/libs/classes/Mibew/Controller/Settings/PerformanceController.php index b2c53468..fd1b526a 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Settings/PerformanceController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Settings/PerformanceController.php @@ -180,7 +180,6 @@ class PerformanceController extends AbstractController foreach ($params as $key => $value) { Settings::set($key, $value); } - Settings::update(); // Redirect the current operator to the same page using get method. $redirect_to = $this->generateUrl('settings_performance', array('stored' => true)); diff --git a/src/mibew/libs/classes/Mibew/Settings.php b/src/mibew/libs/classes/Mibew/Settings.php index 6b61dfe8..58302138 100644 --- a/src/mibew/libs/classes/Mibew/Settings.php +++ b/src/mibew/libs/classes/Mibew/Settings.php @@ -158,27 +158,21 @@ class Settings public static function set($name, $value) { $instance = self::getInstance(); + // Update value in the instance $instance->settings[$name] = $value; - } - /** - * Updates settings in database. - */ - public static function update() - { - $instance = self::getInstance(); + // Update value in the database $db = Database::getInstance(); - foreach ($instance->settings as $key => $value) { - if (!isset($instance->settingsInDb[$key])) { - $db->query( - "INSERT INTO {config} (vckey) VALUES (?)", - array($key) - ); - $instance->settingsInDb[$key] = true; - } + if (!isset($instance->settingsInDb[$name])) { $db->query( - "UPDATE {config} SET vcvalue=? WHERE vckey=?", - array($value, $key) + "INSERT INTO {config} (vckey, vcvalue) VALUES (:name, :value)", + array(':name' => $name, ':value' => $value) + ); + $instance->settingsInDb[$name] = true; + } else { + $db->query( + 'UPDATE {config} SET vcvalue=:value WHERE vckey=:name', + array(':name' => $name, ':value' => $value) ); } } diff --git a/src/mibew/libs/classes/Mibew/Style/ChatStyle.php b/src/mibew/libs/classes/Mibew/Style/ChatStyle.php index e7644657..d6b9e119 100644 --- a/src/mibew/libs/classes/Mibew/Style/ChatStyle.php +++ b/src/mibew/libs/classes/Mibew/Style/ChatStyle.php @@ -117,7 +117,6 @@ class ChatStyle extends AbstractHandlebarsPoweredStyle implements StyleInterface public static function setDefaultStyle($style_name) { Settings::set('chat_style', $style_name); - Settings::update(); } /** diff --git a/src/mibew/libs/classes/Mibew/Style/InvitationStyle.php b/src/mibew/libs/classes/Mibew/Style/InvitationStyle.php index c8ad0212..4c1334a2 100644 --- a/src/mibew/libs/classes/Mibew/Style/InvitationStyle.php +++ b/src/mibew/libs/classes/Mibew/Style/InvitationStyle.php @@ -82,7 +82,6 @@ class InvitationStyle extends AbstractStyle implements StyleInterface public static function setDefaultStyle($style_name) { Settings::set('invitation_style', $style_name); - Settings::update(); } /** diff --git a/src/mibew/libs/classes/Mibew/Style/PageStyle.php b/src/mibew/libs/classes/Mibew/Style/PageStyle.php index 7bb93f76..19e4771b 100644 --- a/src/mibew/libs/classes/Mibew/Style/PageStyle.php +++ b/src/mibew/libs/classes/Mibew/Style/PageStyle.php @@ -95,7 +95,6 @@ class PageStyle extends AbstractHandlebarsPoweredStyle implements StyleInterface public static function setDefaultStyle($style_name) { Settings::set('page_style', $style_name); - Settings::update(); } /**