r110460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110459‎ | r110460 | r110461 >
Date:04:44, 1 February 2012
Author:aaron
Status:ok
Tags:core 
Comment:
Deferred File::getLocalRef() in BitmapHandler and altered MediaTransformOutput to compensate. They were getting called on every getTransform() call, which are triggered by just looking at pages with files (like Special:ListFiles). This made page loads very slow for non-FS backends.
Modified paths:
  • /trunk/phase3/includes/media/Bitmap.php (modified) (history)
  • /trunk/phase3/includes/media/MediaTransformOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/MediaTransformOutput.php
@@ -86,35 +86,43 @@
8787 }
8888
8989 /**
90 - * Check if an output thumbnail file was actually made.
 90+ * Check if an output thumbnail file actually exists.
9191 * This will return false if there was an error, the
92 - * thumnail is to be handled client-side only, or if
 92+ * thumbnail is to be handled client-side only, or if
9393 * transformation was deferred via TRANSFORM_LATER.
94 - *
 94+ *
9595 * @return Bool
9696 */
9797 public function hasFile() {
98 - // If TRANSFORM_LATER, $this->path will be false
99 - return ( !$this->isError() && $this->path );
 98+ // If TRANSFORM_LATER, $this->path will be false.
 99+ // Note: a null path means "use the source file".
 100+ return ( !$this->isError() && ( $this->path || $this->path === null ) );
100101 }
101102
102103 /**
103 - * Check if the output thumbnail file is the same as the source.
 104+ * Check if the output thumbnail is the same as the source.
104105 * This can occur if the requested width was bigger than the source.
105106 *
106107 * @return Bool
107108 */
108109 public function fileIsSource() {
109 - return ( !$this->isError() && $this->path === $this->file->getLocalRefPath() );
 110+ return ( !$this->isError() && $this->path === null );
110111 }
111112
112113 /**
113 - * Get the path of a file system copy of the thumbnail
 114+ * Get the path of a file system copy of the thumbnail.
 115+ * Callers should never write to this path.
114116 *
115117 * @return string|false Returns false if there isn't one
116118 */
117119 public function getLocalCopyPath() {
118 - return $this->path;
 120+ if ( $this->isError() ) {
 121+ return false;
 122+ } elseif ( $this->path === null ) {
 123+ return $this->file->getLocalRefPath();
 124+ } else {
 125+ return $this->path; // may return false
 126+ }
119127 }
120128
121129 /**
@@ -124,7 +132,7 @@
125133 * @return Bool success
126134 */
127135 public function streamFile( $headers = array() ) {
128 - return $this->path && StreamFile::stream( $this->path, $headers );
 136+ return $this->path && StreamFile::stream( $this->getLocalCopyPath(), $headers );
129137 }
130138
131139 /**
@@ -170,13 +178,16 @@
171179 * @ingroup Media
172180 */
173181 class ThumbnailImage extends MediaTransformOutput {
174 -
175182 /**
 183+ * Get a thumbnail object from a file and parameters.
 184+ * If $path is set to null, the output file is treated as a source copy.
 185+ * If $path is set to false, no output file will be created.
 186+ *
176187 * @param $file File object
177188 * @param $url String: URL path to the thumb
178189 * @param $width Integer: file's width
179190 * @param $height Integer: file's height
180 - * @param $path String: filesystem path to the thumb
 191+ * @param $path String|false|null: filesystem path to the thumb
181192 * @param $page Integer: page number, for multipage files
182193 * @private
183194 */
Index: trunk/phase3/includes/media/Bitmap.php
@@ -125,7 +125,6 @@
126126 'srcWidth' => $image->getWidth(),
127127 'srcHeight' => $image->getHeight(),
128128 'mimeType' => $image->getMimeType(),
129 - 'srcPath' => $image->getLocalRefPath(),
130129 'dstPath' => $dstPath,
131130 'dstUrl' => $dstUrl,
132131 );
@@ -163,6 +162,9 @@
164163 return $this->getClientScalingThumbnailImage( $image, $scalerParams );
165164 }
166165
 166+ # Transform functions and binaries need a FS source file
 167+ $scalerParams['srcPath'] = $image->getLocalRefPath();
 168+
167169 # Try a hook
168170 $mto = null;
169171 wfRunHooks( 'BitmapHandlerTransform', array( $this, $image, &$scalerParams, &$mto ) );
@@ -248,7 +250,7 @@
249251 */
250252 protected function getClientScalingThumbnailImage( $image, $params ) {
251253 return new ThumbnailImage( $image, $image->getURL(),
252 - $params['clientWidth'], $params['clientHeight'], $params['srcPath'] );
 254+ $params['clientWidth'], $params['clientHeight'], null );
253255 }
254256
255257 /**

Status & tagging log