From 5b70e2fb25a3228d46eb7ceaa497b957f8755d1e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 25 Apr 2012 00:11:10 +0200 Subject: [PATCH] some performance improvements to the openstack swift backend --- apps/files_external/lib/swift.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e53eb1ff3b..a987d17d79 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -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);