]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache: only look for child entires when doing a move operation when moving a folder
authorRobin Appelman <icewind@owncloud.com>
Fri, 19 Apr 2013 13:03:59 +0000 (15:03 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 8 May 2013 20:35:38 +0000 (22:35 +0200)
lib/files/cache/cache.php
tests/lib/files/cache/cache.php

index 71b70abe3fec5f586cf3f191e3fc8bc6b7d97c39..d30c5cd16edaa70ba3fdc082b3062617b9846b2f 100644 (file)
@@ -205,7 +205,7 @@ class Cache {
                                . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
                        $result = $query->execute($params);
                        if (\OC_DB::isError($result)) {
-                               \OCP\Util::writeLog('cache', 'Insert to cache failed: '.$result, \OCP\Util::ERROR);
+                               \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR);
                        }
 
                        return (int)\OC_DB::insertid('*PREFIX*filecache');
@@ -328,19 +328,22 @@ class Cache {
         * @param string $target
         */
        public function move($source, $target) {
-               $sourceId = $this->getId($source);
+               $sourceData = $this->get($source);
+               $sourceId = $sourceData['fileid'];
                $newParentId = $this->getParentId($target);
 
-               //find all child entries
-               $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?');
-               $result = $query->execute(array($source . '/%'));
-               $childEntries = $result->fetchAll();
-               $sourceLength = strlen($source);
-               $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
-
-               foreach ($childEntries as $child) {
-                       $targetPath = $target . substr($child['path'], $sourceLength);
-                       $query->execute(array($targetPath, md5($targetPath), $child['fileid']));
+               if ($sourceData['mimetype'] === 'httpd/unix-directory') {
+                       //find all child entries
+                       $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?');
+                       $result = $query->execute(array($source . '/%'));
+                       $childEntries = $result->fetchAll();
+                       $sourceLength = strlen($source);
+                       $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
+
+                       foreach ($childEntries as $child) {
+                               $targetPath = $target . substr($child['path'], $sourceLength);
+                               $query->execute(array($targetPath, md5($targetPath), $child['fileid']));
+                       }
                }
 
                $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?'
index 250842805e5d32072fc253a5c6fc892baf008594..4051a6e234b4177e5d041a73e0f783dbbb4d7603 100644 (file)
@@ -162,10 +162,11 @@ class Cache extends \PHPUnit_Framework_TestCase {
                $file4 = 'folder/foo/1';
                $file5 = 'folder/foo/2';
                $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar');
+               $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
 
-               $this->cache->put($file1, $data);
-               $this->cache->put($file2, $data);
-               $this->cache->put($file3, $data);
+               $this->cache->put($file1, $folderData);
+               $this->cache->put($file2, $folderData);
+               $this->cache->put($file3, $folderData);
                $this->cache->put($file4, $data);
                $this->cache->put($file5, $data);