]> source.dussan.org Git - nextcloud-server.git/commitdiff
reuse cacheentry
authorRobin Appelman <robin@icewind.nl>
Tue, 13 Dec 2016 11:30:29 +0000 (12:30 +0100)
committerRobin Appelman <robin@icewind.nl>
Tue, 13 Dec 2016 11:30:29 +0000 (12:30 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_sharing/lib/SharedMount.php

index 5436f476f1a6ad4aee166631f020a569818f1be1..b7fb96b711b60191282b30d0e2de278f449180b5 100644 (file)
@@ -130,12 +130,12 @@ class SharedMount extends MountPoint implements MoveableMount {
         */
        private function generateUniqueTarget($path, $view, array $mountpoints) {
                $pathinfo = pathinfo($path);
-               $ext = (isset($pathinfo['extension'])) ? '.'.$pathinfo['extension'] : '';
+               $ext = (isset($pathinfo['extension'])) ? '.' . $pathinfo['extension'] : '';
                $name = $pathinfo['filename'];
                $dir = $pathinfo['dirname'];
 
                // Helper function to find existing mount points
-               $mountpointExists = function($path) use ($mountpoints) {
+               $mountpointExists = function ($path) use ($mountpoints) {
                        foreach ($mountpoints as $mountpoint) {
                                if ($mountpoint->getShare()->getTarget() === $path) {
                                        return true;
@@ -146,7 +146,7 @@ class SharedMount extends MountPoint implements MoveableMount {
 
                $i = 2;
                while ($view->file_exists($path) || $mountpointExists($path)) {
-                       $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
+                       $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
                        $i++;
                }
 
@@ -240,18 +240,22 @@ class SharedMount extends MountPoint implements MoveableMount {
         * @return int
         */
        public function getNumericStorageId() {
-               $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
-
-               $query = $builder->select('storage')
-                       ->from('filecache')
-                       ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId())));
-
-               $result = $query->execute();
-               $row = $result->fetch();
-               $result->closeCursor();
-               if ($row) {
-                       return $row['storage'];
+               if (!is_null($this->getShare()->getNodeCacheEntry())) {
+                       return $this->getShare()->getNodeCacheEntry()->getStorageId();
+               } else {
+                       $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+
+                       $query = $builder->select('storage')
+                               ->from('filecache')
+                               ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId())));
+
+                       $result = $query->execute();
+                       $row = $result->fetch();
+                       $result->closeCursor();
+                       if ($row) {
+                               return $row['storage'];
+                       }
+                       return -1;
                }
-               return -1;
        }
 }