]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache: don't insert duplicated during upgrade
authorRobin Appelman <icewind@owncloud.com>
Wed, 30 Jan 2013 17:17:56 +0000 (18:17 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 30 Jan 2013 18:19:19 +0000 (19:19 +0100)
lib/files/cache/upgrade.php

index 19e3d9ad57584083eb99748d8484b88c21169fa7..eb8c7297c3e6938b7f0f229697318c9777283546 100644 (file)
@@ -64,12 +64,25 @@ class Upgrade {
         * @param array $data the data for the new cache
         */
        function insert($data) {
-               $insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`
-                               ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
-                               VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
+               if (!$this->inCache($data['storage'], $data['path_hash'])) {
+                       $insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`
+                                       ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` )
+                                       VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
 
-               $insertQuery->execute(array($data['id'], $data['storage'], $data['path'], $data['path_hash'], $data['parent'], $data['name'],
-                       $data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted']));
+                       $insertQuery->execute(array($data['id'], $data['storage'], $data['path'], $data['path_hash'], $data['parent'], $data['name'],
+                               $data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted']));
+               }
+       }
+
+       /**
+        * @param string $storage
+        * @param string $pathHash
+        * @return bool
+        */
+       function inCache($storage, $pathHash) {
+               $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
+               $result = $query->execute(array($storage, $pathHash));
+               return (bool)$result->fetchRow();
        }
 
        /**