From df313a0aeb2487a22ef4a93d70a2ecbeaa23df43 Mon Sep 17 00:00:00 2001 From: SargTeX Date: Fri, 3 Aug 2012 21:34:26 +0300 Subject: [PATCH] Added check to avoid senseless update queries I just added some code that checks wether any data of the object changed or not. Makes it easier to use for developers. If no value changed, the object won't be updated. --- .../files/lib/data/DatabaseObjectEditor.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php b/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php index fb5bce8d15..193ffdc6b5 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php @@ -53,6 +53,18 @@ abstract class DatabaseObjectEditor extends DatabaseObjectDecorator implements I public function update(array $parameters = array()) { if (!count($parameters)) return; + //check wether any value changed or not + $update = false; + foreach($parameters as $name => $value) { + if ($this->__get($name) != $value) { + $update = true; + break; + } + } + + //there is no new data - break to avoid senseless sql queries + if (!$update) return; + $updateSQL = ''; $statementParameters = array(); foreach ($parameters as $key => $value) { -- 2.20.1