r106978 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106977‎ | r106978 | r106979 >
Date:20:39, 21 December 2011
Author:aaron
Status:ok
Tags:
Comment:
* Added FileRepo::SKIP_LOCKING constant and made storeBatch() check it.
* Made File::maybeDoTransform() use the FileRepo::store() and a new File::getThumbRel() function. Looks cleaner and loosens FileBackend coupling.
* Also made storeTemp() use FileRepo::SKIP_LOCKING for performance.
* Killed some useless initZones() calls in FileRepo. Extensions may not even use these zones. Likewise, it could make tests fail even though they don't those zones. We already do the sanity with some prepare() calls in storeBatch().
* Removed FileRepo::SKIP_VALIDATION, not used by anything now.
* Moved getUrlRel() down a bit.
Modified paths:
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/file/File.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/file/File.php
@@ -799,12 +799,11 @@
800800 $thumb = $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params );
801801 }
802802 } elseif ( $thumb->hasFile() && !$thumb->fileIsSource() ) {
803 - // @TODO: use a FileRepo store function
804 - $op = array( 'op' => 'store',
805 - 'src' => $tmpThumbPath, 'dst' => $thumbPath, 'overwriteDest' => true );
806803 // Copy any thumbnail from the FS into storage at $dstpath
807 - $opts = array( 'ignoreErrors' => true, 'nonLocking' => true ); // performance
808 - if ( !$this->getRepo()->getBackend()->doOperation( $op, $opts )->isOK() ) {
 804+ $status = $this->repo->store(
 805+ $tmpThumbPath, 'thumb', $this->getThumbRel( $thumbName ),
 806+ FileRepo::OVERWRITE | FileRepo::SKIP_LOCKING );
 807+ if ( !$status->isOK() ) {
809808 return new MediaTransformError( 'thumbnail_error',
810809 $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) );
811810 }
@@ -1013,7 +1012,8 @@
10141013 }
10151014
10161015 /**
1017 - * Get the path of the file relative to the public zone root
 1016+ * Get the path of the file relative to the public zone root.
 1017+ * This function is overriden in OldLocalFile to be like getArchiveRel().
10181018 *
10191019 * @return string
10201020 */
@@ -1022,17 +1022,8 @@
10231023 }
10241024
10251025 /**
1026 - * Get urlencoded relative path of the file
 1026+ * Get the path of an archived file relative to the public zone root
10271027 *
1028 - * @return string
1029 - */
1030 - function getUrlRel() {
1031 - return $this->getHashPath() . rawurlencode( $this->getName() );
1032 - }
1033 -
1034 - /**
1035 - * Get the relative path for an archived file
1036 - *
10371028 * @param $suffix bool|string if not false, the name of an archived thumbnail file
10381029 *
10391030 * @return string
@@ -1048,7 +1039,33 @@
10491040 }
10501041
10511042 /**
1052 - * Get the relative path for an archived file's thumbs directory
 1043+ * Get the path, relative to the thumbnail zone root, of the
 1044+ * thumbnail directory or a particular file if $suffix is specified
 1045+ *
 1046+ * @param $suffix bool|string if not false, the name of a thumbnail file
 1047+ *
 1048+ * @return string
 1049+ */
 1050+ function getThumbRel( $suffix = false ) {
 1051+ $path = $this->getRel();
 1052+ if ( $suffix !== false ) {
 1053+ $path .= '/' . $suffix;
 1054+ }
 1055+ return $path;
 1056+ }
 1057+
 1058+ /**
 1059+ * Get urlencoded path of the file relative to the public zone root.
 1060+ * This function is overriden in OldLocalFile to be like getArchiveUrl().
 1061+ *
 1062+ * @return string
 1063+ */
 1064+ function getUrlRel() {
 1065+ return $this->getHashPath() . rawurlencode( $this->getName() );
 1066+ }
 1067+
 1068+ /**
 1069+ * Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory
10531070 * or a specific thumb if the $suffix is given.
10541071 *
10551072 * @param $archiveName string the timestamped name of an archived image
@@ -1079,7 +1096,7 @@
10801097 }
10811098
10821099 /**
1083 - * Get the path of the archived file's thumbs, or a particular thumb if $suffix is specified
 1100+ * Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified
10841101 *
10851102 * @param $archiveName string the timestamped name of an archived image
10861103 * @param $suffix bool|string if not false, the name of a thumbnail file
@@ -1101,11 +1118,7 @@
11021119 */
11031120 function getThumbPath( $suffix = false ) {
11041121 $this->assertRepoDefined();
1105 - $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getRel();
1106 - if ( $suffix !== false ) {
1107 - $path .= '/' . $suffix;
1108 - }
1109 - return $path;
 1122+ return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
11101123 }
11111124
11121125 /**
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -13,10 +13,11 @@
1414 */
1515 class FileRepo {
1616 const FILES_ONLY = 1;
 17+
1718 const DELETE_SOURCE = 1;
1819 const OVERWRITE = 2;
1920 const OVERWRITE_SAME = 4;
20 - const SKIP_VALIDATION = 8;
 21+ const SKIP_LOCKING = 8;
2122
2223 /** @var FileBackendBase */
2324 protected $backend;
@@ -622,6 +623,7 @@
623624 * self::OVERWRITE Overwrite an existing destination file instead of failing
624625 * self::OVERWRITE_SAME Overwrite the file if the destination exists and has the
625626 * same contents as the source
 627+ * self::SKIP_LOCKING Skip any file locking when doing the store
626628 * @return FileRepoStatus
627629 */
628630 public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
@@ -641,17 +643,12 @@
642644 * self::OVERWRITE Overwrite an existing destination file instead of failing
643645 * self::OVERWRITE_SAME Overwrite the file if the destination exists and has the
644646 * same contents as the source
 647+ * self::SKIP_LOCKING Skip any file locking when doing the store
645648 * @return FileRepoStatus
646649 */
647650 public function storeBatch( $triplets, $flags = 0 ) {
648651 $backend = $this->backend; // convenience
649652
650 - // Try creating directories
651 - $status = $this->initZones();
652 - if ( !$status->isOK() ) {
653 - return $status;
654 - }
655 -
656653 $status = $this->newGood();
657654
658655 $operations = array();
@@ -705,6 +702,9 @@
706703
707704 // Execute the store operation for each triplet
708705 $opts = array( 'ignoreErrors' => true );
 706+ if ( $flags & self::SKIP_LOCKING ) {
 707+ $opts['nonLocking'] = true;
 708+ }
709709 $status->merge( $backend->doOperations( $operations, $opts ) );
710710 // Cleanup for disk source files...
711711 foreach ( $sourceFSFilesToDelete as $file ) {
@@ -778,7 +778,7 @@
779779 $dstRel = "{$hashPath}{$date}!{$originalName}";
780780 $dstUrlRel = $hashPath . $date . '!' . rawurlencode( $originalName );
781781
782 - $result = $this->store( $srcPath, 'temp', $dstRel );
 782+ $result = $this->store( $srcPath, 'temp', $dstRel, self::SKIP_LOCKING );
783783 $result->value = $this->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
784784 return $result;
785785 }
@@ -1005,9 +1005,6 @@
10061006 * @return Either array of files and existence flags, or false
10071007 */
10081008 public function fileExistsBatch( $files, $flags = 0 ) {
1009 - if ( !$this->initZones() ) {
1010 - return false;
1011 - }
10121009 $result = array();
10131010 foreach ( $files as $key => $file ) {
10141011 if ( self::isVirtualUrl( $file ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r108185Partially reverted r108111: we can't assume subclasses put thumbnails in the....aaron23:35, 5 January 2012

Status & tagging log