From 6f3836da797aa92fbba0d3eebe4563828d2ed6b9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 11 Apr 2014 16:05:12 -0700 Subject: [PATCH] Wrap djvu large local copy downloads in pool counter Change-Id: I3cade9d870f7c344434d7cee27506d53345ebdf9 --- includes/media/DjVu.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index 1202c9a2ed..4e0f44c326 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -177,7 +177,33 @@ class DjVuHandler extends ImageHandler { ); } - $srcPath = $image->getLocalRefPath(); + // Get local copy source for shell scripts + // 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( 'GetLocalFileCopy', sha1( $image->getName() ), + array( + 'doWork' => function() use ( $image ) { + return $image->getLocalRefPath(); + } + ) + ); + $srcPath = $work->execute(); + } else { + $srcPath = $image->getLocalRefPath(); + } + + if ( $srcPath === false ) { // Failed to get local copy + wfDebugLog( 'thumbnail', + sprintf( 'Thumbnail failed on %s: could not get local copy of "%s"', + wfHostname(), $image->getName() ) ); + + return new MediaTransformError( 'thumbnail_error', + $params['width'], $params['height'], + wfMessage( 'filemissing' )->text() + ); + } + # Use a subshell (brackets) to aggregate stderr from both pipeline commands # before redirecting it to the overall stdout. This works in both Linux and Windows XP. $cmd = '(' . wfEscapeShellArg( -- 2.20.1