]> source.dussan.org Git - nextcloud-server.git/commitdiff
don't update identical values
authorJens-Christian Fischer <jens-christian.fischer@switch.ch>
Sat, 11 Apr 2015 16:06:21 +0000 (18:06 +0200)
committerJens-Christian Fischer <jens-christian.fischer@switch.ch>
Sat, 11 Apr 2015 16:06:21 +0000 (18:06 +0200)
The UPDATE oc_filecache statement blindly overwrites identical data.
Databases like Postgres that create a new row on an update
and mark the old one as dead will suffer from the previous
behaviour, as millions of "new" rows are created in the database.

This patch changes the WHERE clause to test for identical
values and not updating if the values in the DB are identical
to the ones being passed.

lib/private/files/cache/cache.php

index c5e118946e5d6b37a81bdf424cbd3813cea75c66..70da3dc776d1c3171b79f234e13a4d5904f81463 100644 (file)
@@ -306,10 +306,16 @@ class Cache {
                }
 
                list($queryParts, $params) = $this->buildParts($data);
+
+               $params = array_merge($params, $params);
                $params[] = $id;
 
-               $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? WHERE `fileid` = ?';
+               // don't update if the data we try to set is the same as the one in the record
+               // some databases (Postgres) don't like superfluous updates
+               $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' .
+                       'WHERE (' . implode(' <> ? OR ', $queryParts) . ' <> ? ) AND `fileid` = ? ';
                \OC_DB::executeAudited($sql, $params);
+
        }
 
        /**