Make GetLocalFileCopy pool counter call from tiff be generic
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 27 Jul 2014 23:23:55 +0000 (20:23 -0300)
committerReedy <reedy@wikimedia.org>
Tue, 16 Sep 2014 20:07:54 +0000 (20:07 +0000)
I was to make PagedTiffHandler subclass TransformationalImageHandler.
The biggest thing that's different is the pool counter call.
However, given that a file is just as expensive in terms of
network bandwidth regardless of its type, seems to make sense
to make this check generic.

Change-Id: I7e4a4769edaa4742803df407b9c719c54fb77de3

includes/filerepo/file/File.php

index f9e0a2d..11a3e5c 100644 (file)
@@ -1231,9 +1231,25 @@ abstract class File {
                        }
                }
 
+               // Thumbnailing a very large file could result in network saturation if
+               // everyone does it at once.
+               if ( $this->getSize() >= 1e7 ) { // 10MB
+                       $that = $this;
+                       $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
+                               array(
+                                       'doWork' => function() use ( $that ) {
+                                               return $that->getLocalRefPath();
+                                       }
+                               )
+                       );
+                       $srcPath = $work->execute();
+               } else {
+                       $srcPath = $this->getLocalRefPath();
+               }
+
                // Original file
                return array(
-                       'path' => $this->getLocalRefPath(),
+                       'path' => $srcPath,
                        'width' => $this->getWidth(),
                        'height' => $this->getHeight()
                );