Added check to avoid senseless update queries
authorSargTeX <sargtex@post.myonid.de>
Fri, 3 Aug 2012 18:34:26 +0000 (21:34 +0300)
committerSargTeX <sargtex@post.myonid.de>
Fri, 3 Aug 2012 18:34:26 +0000 (21:34 +0300)
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.

wcfsetup/install/files/lib/data/DatabaseObjectEditor.class.php

index fb5bce8d15c12bd5c3f58cce8abfa92c7db141df..193ffdc6b5fca28ecea73838005b7bae082878c0 100644 (file)
@@ -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) {