Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/118819

Change subject: Allow using PoolCounter for large PDF local downloads
......................................................................

Allow using PoolCounter for large PDF local downloads

Change-Id: Ifee3a5764b32ef31e4ed9edb183272ebb89bd11b
---
M PdfHandler_body.php
1 file changed, 18 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PdfHandler 
refs/changes/19/118819/1

diff --git a/PdfHandler_body.php b/PdfHandler_body.php
index 495f3bb..32252a5 100644
--- a/PdfHandler_body.php
+++ b/PdfHandler_body.php
@@ -165,7 +165,24 @@
                        return $this->doThumbError( $width, $height, 
'thumbnail_dest_directory' );
                }
 
-               $srcPath = $image->getLocalRefPath();
+               // Thumbnail extraction is very inefficient for large files.
+               // Provide a way to pool count limit the number of downloaders.
+               if ( $image->getSize() >= 1e7 ) { // 10MB
+                       $work = new PoolCounterWorkViaCallback( 'downloadpdf', 
sha1( $image->getName() ),
+                               array(
+                                       'doWork' => function() use ( $image ) {
+                                               return 
$image->getLocalRefPath();
+                                       }
+                               )
+                       );
+                       $srcPath = $work->execute();
+               } else {
+                       $srcPath = $image->getLocalRefPath();
+               }
+
+               if ( $srcPath === false ) { // could not download original
+                       return $this->doThumbError( $width, $height, 
'filemissing' );
+               }
 
                $cmd = '(' . wfEscapeShellArg(
                        $wgPdfProcessor,

-- 
To view, visit https://gerrit.wikimedia.org/r/118819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifee3a5764b32ef31e4ed9edb183272ebb89bd11b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PdfHandler
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to