From: Aaron Schulz Date: Thu, 26 Jan 2012 20:17:18 +0000 (+0000) Subject: Further reduced RTTs in SwiftFileBackend by making "file already exists" checks use... X-Git-Tag: 1.31.0-rc.0~25076 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=b3a3f86a5aa43705f90afe1bb80b4bcb50115e3a;p=lhc%2Fweb%2Fwiklou.git Further reduced RTTs in SwiftFileBackend by making "file already exists" checks use the stat cache, typically already set in FileOp::doPrecheck(). FileBackendBase::doOperationsInternal() already clears the cache after locking (and before FileOp::attemptBatch) for consistency. --- diff --git a/includes/filerepo/backend/SwiftFileBackend.php b/includes/filerepo/backend/SwiftFileBackend.php index b5d2aaae50..ca5e129871 100644 --- a/includes/filerepo/backend/SwiftFileBackend.php +++ b/includes/filerepo/backend/SwiftFileBackend.php @@ -108,13 +108,11 @@ class SwiftFileBackend extends FileBackend { // (a) Check the destination container and object try { $dContObj = $this->getContainer( $dstCont ); - if ( empty( $params['overwrite'] ) ) { - $destObj = $dContObj->create_object( $dstRel ); - // Check if the object already exists (fields populated) - if ( $destObj->last_modified ) { - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); - return $status; - } + if ( empty( $params['overwrite'] ) && + $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) ) + { + $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); + return $status; } } catch ( NoSuchContainerException $e ) { $status->fatal( 'backend-fail-create', $params['dst'] ); @@ -172,13 +170,11 @@ class SwiftFileBackend extends FileBackend { // (a) Check the destination container and object try { $dContObj = $this->getContainer( $dstCont ); - if ( empty( $params['overwrite'] ) ) { - $destObj = $dContObj->create_object( $dstRel ); - // Check if the object already exists (fields populated) - if ( $destObj->last_modified ) { - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); - return $status; - } + if ( empty( $params['overwrite'] ) && + $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) ) + { + $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); + return $status; } } catch ( NoSuchContainerException $e ) { $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); @@ -249,13 +245,11 @@ class SwiftFileBackend extends FileBackend { try { $sContObj = $this->getContainer( $srcCont ); $dContObj = $this->getContainer( $dstCont ); - if ( empty( $params['overwrite'] ) ) { - $destObj = $dContObj->create_object( $dstRel ); - // Check if the object already exists (fields populated) - if ( $destObj->last_modified ) { - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); - return $status; - } + if ( empty( $params['overwrite'] ) && + $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) ) + { + $status->fatal( 'backend-fail-alreadyexists', $params['dst'] ); + return $status; } } catch ( NoSuchContainerException $e ) { $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); @@ -478,13 +472,16 @@ class SwiftFileBackend extends FileBackend { return false; // invalid storage path } + if ( !$this->fileExists( $params ) ) { + return null; + } + $data = false; try { - $container = $this->getContainer( $srcCont ); - $obj = $container->get_object( $srcRel ); + $sContObj = $this->getContainer( $srcCont ); + $obj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD request $data = $obj->read( $this->headersFromParams( $params ) ); } catch ( NoSuchContainerException $e ) { - } catch ( NoSuchObjectException $e ) { } catch ( InvalidResponseException $e ) { } catch ( Exception $e ) { // some other exception? $this->logException( $e, __METHOD__, $params ); @@ -587,10 +584,14 @@ class SwiftFileBackend extends FileBackend { return null; } + if ( !$this->fileExists( $params ) ) { + return null; + } + $tmpFile = null; try { - $cont = $this->getContainer( $srcCont ); - $obj = $cont->get_object( $srcRel ); + $sContObj = $this->getContainer( $srcCont ); + $obj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD // Get source file extension $ext = FileBackend::extensionFromPath( $srcRel ); // Create a new temporary file... @@ -606,8 +607,6 @@ class SwiftFileBackend extends FileBackend { } } catch ( NoSuchContainerException $e ) { $tmpFile = null; - } catch ( NoSuchObjectException $e ) { - $tmpFile = null; } catch ( InvalidResponseException $e ) { $tmpFile = null; } catch ( Exception $e ) { // some other exception?