]> source.dussan.org Git - nextcloud-server.git/commitdiff
some performance improvements to the openstack swift backend
authorRobin Appelman <icewind@owncloud.com>
Tue, 24 Apr 2012 22:11:10 +0000 (00:11 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 24 Apr 2012 22:12:12 +0000 (00:12 +0200)
apps/files_external/lib/swift.php

index e53eb1ff3b6fd1d92a9befaed1612f8b9222a1fd..a987d17d799c49bfa741e698c4a3deedcf9ba8ec 100644 (file)
@@ -28,6 +28,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
        private $rootContainer;
 
        private static $tempFiles=array();
+       private $objects=array();
+       private $containers=array();
 
        const SUBCONTAINER_FILE='.subcontainers';
 
@@ -38,7 +40,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
         */
        private function getContainerName($path){
                $path=trim($this->root.$path,'/');
-               return md5($path);
+               return str_replace('/','\\',$path);
        }
 
        /**
@@ -50,8 +52,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                if($path=='' or $path=='/'){
                        return $this->rootContainer;
                }
+               if(isset($this->containers[$path])){
+                       return $this->containers[$path];
+               }
                try{
                        $container=$this->conn->get_container($this->getContainerName($path));
+                       $this->containers[$path]=$container;
                        return $container;
                }catch(NoSuchContainerException $e){
                        return null;
@@ -87,12 +93,16 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
         * @return CF_Object
         */
        private function getObject($path){
+               if(isset($this->objects[$path])){
+                       return $this->objects[$path];
+               }
                $container=$this->getContainer(dirname($path));
                if(is_null($container)){
                        return null;
                }else{
                        try{
                                $obj=$container->get_object(basename($path));
+                               $this->objects[$path]=$obj;
                                return $obj;
                        }catch(NoSuchObjectException $e){
                                return null;
@@ -295,6 +305,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                        }
                        
                        $this->conn->delete_container($this->getContainerName($path));
+                       unset($this->containers[$path]);
                        return true;
                }
        }
@@ -309,12 +320,14 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                        if($sub){
                                $this->emptyContainer($path.'/'.$sub);
                                $this->conn->delete_container($this->getContainerName($path.'/'.$sub));
+                               unset($this->containers[$path.'/'.$sub]);
                        }
                }
 
                $objects=$this->getObjects($container);
                foreach($objects as $object){
                        $container->delete_object($object);
+                       unset($this->objects[$path.'/'.$object]);
                }
        }
 
@@ -381,6 +394,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                if($this->objectExists($path)){
                        $container=$this->getContainer(dirname($path));
                        $container->delete_object(basename($path));
+                       unset($this->objects[$path]);
                }else{
                        return false;
                }
@@ -447,6 +461,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
                $sourceContainer=$this->getContainer(dirname($path1));
                $targetContainer=$this->getContainer(dirname($path2));
                $result=$sourceContainer->move_object_to(basename($path1),$targetContainer,basename($path2));
+               unset($this->objects[$path1]);
                if($result){
                        $targetObj=$this->getObject($path2);
                        $this->resetMTime($targetObj);