From: Brad Jorsch Date: Fri, 1 Feb 2013 23:14:09 +0000 (-0500) Subject: Limit ApiQueryImageInfo transform calls X-Git-Tag: 1.31.0-rc.0~20623 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=89a222dd861917f6d34f5637a269322a22528d42;p=lhc%2Fweb%2Fwiklou.git Limit ApiQueryImageInfo transform calls Apparently calls to File::transform can be slow. Add code to limit these calls in prop=imageinfo. The only effect for clients will be a possibility of seeing iicontinue more often. Once this is merged, TimedMediaHandler's ApiQueryVideoInfo.php should be updated in the same way. Change-Id: Id0ec6a0afb85ca73eefb5b8370c2147c37f037e9 --- diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 6e811fc71e..3afd4bf50c 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -219,6 +219,8 @@ production. * Add supports for all pageset capabilities - generators, redirects, converttitles to action=purge and action=setnotificationtimestamp. * (bug 43251) prop=pageprops&ppprop= now accepts multiple props to query. +* ApiQueryImageInfo will now limit the number of calls to File::transform made + in any one query. If there are too many, iicontinue will be returned. === API internal changes in 1.21 === * For debugging only, a new global $wgDebugAPI removes many API restrictions when true. diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 351753c7a2..34f78e7820 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -30,6 +30,8 @@ * @ingroup API */ class ApiQueryImageInfo extends ApiQueryBase { + const TRANSFORM_LIMIT = 50; + private static $transformCount = 0; public function __construct( $query, $moduleName, $prefix = 'ii' ) { // We allow a subclass to override the prefix, to create a related API module. @@ -90,6 +92,19 @@ class ApiQueryImageInfo extends ApiQueryBase { $img = $images[$title]; + if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) { + if ( count( $pageIds[NS_FILE] ) == 1 ) { + // See the 'the user is screwed' comment below + $this->setContinueEnumParameter( 'start', + $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) + ); + } else { + $this->setContinueEnumParameter( 'continue', + $this->getContinueStr( $img, $start ) ); + } + break; + } + $fit = $result->addValue( array( 'query', 'pages', intval( $pageId ) ), 'imagerepository', $img->getRepoName() @@ -337,6 +352,7 @@ class ApiQueryImageInfo extends ApiQueryBase { if ( $url ) { if ( !is_null( $thumbParams ) ) { $mto = $file->transform( $thumbParams ); + self::$transformCount++; if ( $mto && !$mto->isError() ) { $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT ); @@ -396,6 +412,17 @@ class ApiQueryImageInfo extends ApiQueryBase { return $vals; } + /** + * Get the count of image transformations performed + * + * If this is >= TRANSFORM_LIMIT, you should probably stop processing images. + * + * @return integer count + */ + static function getTransformCount() { + return self::$transformCount; + } + /** * * @param $metadata Array