summaryrefslogtreecommitdiffstats
path: root/lib/public/appframework
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-23 13:43:17 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-23 13:43:17 +0200
commit5199e4508ac0c1d3902434a9cd05987d053d40f0 (patch)
treed91739aeac078e7c9a1c50d01afd1bd37221c142 /lib/public/appframework
parent309aa3bcd253d5584ff4b514874ef51a6623a621 (diff)
downloadnextcloud-server-5199e4508ac0c1d3902434a9cd05987d053d40f0.tar.gz
nextcloud-server-5199e4508ac0c1d3902434a9cd05987d053d40f0.zip
dont update entity and dont run an update query if an entity wasnt changed at all
Diffstat (limited to 'lib/public/appframework')
-rw-r--r--lib/public/appframework/db/entity.php3
-rw-r--r--lib/public/appframework/db/mapper.php7
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/public/appframework/db/entity.php b/lib/public/appframework/db/entity.php
index 631bf85061e..8ab42bd9153 100644
--- a/lib/public/appframework/db/entity.php
+++ b/lib/public/appframework/db/entity.php
@@ -92,6 +92,9 @@ abstract class Entity {
protected function setter($name, $args) {
// setters should only work for existing attributes
if(property_exists($this, $name)){
+ if($this->$name === $args[0]) {
+ return;
+ }
$this->markFieldUpdated($name);
// if type definition exists, cast to correct type
diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php
index f65a232ed83..13a4c65e493 100644
--- a/lib/public/appframework/db/mapper.php
+++ b/lib/public/appframework/db/mapper.php
@@ -127,6 +127,12 @@ abstract class Mapper {
* @param Entity $entity the entity that should be created
*/
public function update(Entity $entity){
+ // if entity wasn't changed it makes no sense to run a db query
+ $properties = $entity->getUpdatedFields();
+ if(count($properties) === 0) {
+ return $entity;
+ }
+
// entity needs an id
$id = $entity->getId();
if($id === null){
@@ -136,7 +142,6 @@ abstract class Mapper {
// get updated fields to save, fields have to be set using a setter to
// be saved
- $properties = $entity->getUpdatedFields();
// dont update the id field
unset($properties['id']);