jenkins-bot has submitted this change and it was merged.
Change subject: Limit ApiQueryImageInfo transform calls
......................................................................
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
---
M RELEASE-NOTES-1.21
M includes/api/ApiQueryImageInfo.php
2 files changed, 29 insertions(+), 0 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21
index 6e811fc..3afd4bf 100644
--- a/RELEASE-NOTES-1.21
+++ b/RELEASE-NOTES-1.21
@@ -219,6 +219,8 @@
* 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 351753c..34f78e7 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.
@@ -89,6 +91,19 @@
}
$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 ) ),
@@ -337,6 +352,7 @@
if ( $url ) {
if ( !is_null( $thumbParams ) ) {
$mto = $file->transform( $thumbParams );
+ self::$transformCount++;
if ( $mto && !$mto->isError() ) {
$vals['thumburl'] = wfExpandUrl(
$mto->getUrl(), PROTO_CURRENT );
@@ -397,6 +413,17 @@
}
/**
+ * 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
* @param $result ApiResult
--
To view, visit https://gerrit.wikimedia.org/r/47189
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id0ec6a0afb85ca73eefb5b8370c2147c37f037e9
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits