From: SargTeX Date: Fri, 3 Aug 2012 18:34:26 +0000 (+0300) Subject: Added check to avoid senseless update queries X-Git-Tag: 2.0.0_Beta_1~885^2~3^2~1^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=df313a0aeb2487a22ef4a93d70a2ecbeaa23df43;p=GitHub%2FWoltLab%2FWCF.git 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. --- 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) {