Page MenuHomePhabricator

Consider to cache again InstantCommons requests by default
Closed, InvalidPublic

Description

According https://www.mediawiki.org/wiki/InstantCommons, InstantCommons requests
are only fired once and cached on the server.

But on https://www.mediawiki.org/wiki/Manual:$wgUseInstantCommons, we can read
"Since MediaWiki 1.27, $wgUseInstantCommons hotlinks images from Commons
by default instead of downloading originals and thumbnailing them locally.".

I see on a MediaWiki 1.31 installation several slow php-fpm requests making more than 10 seconds
to fetch 8 small pictures of 32px and a 240px one with the following stack trace.

None of the documented behaviors above are true: MediaWiki makes an heavy use of
outgoing requests each time to get the upload.wikimedia.org links, and so performance
could be rather poor the time all the curl requests are done.

Disabling InstantCommons makes the page loads instantaneously.

[0x0000000802a27bd0] curl_init() /srv/mediawiki/includes/http/CurlHttpRequest.php:107
[0x0000000802a27400] execute() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:532
[0x0000000802a27170] httpGet() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:577
[0x0000000802a26ff0] {closure}() /srv/mediawiki/includes/libs/objectcache/WANObjectCache.php:1240
[0x0000000802a263e0] doGetWithSetCallback() /srv/mediawiki/includes/libs/objectcache/WANObjectCache.php:1114
[0x0000000802a26060] getWithSetCallback() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:587
[0x0000000802a25ec0] httpGetCached() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:203
[0x0000000802a25dc0] fetchImageQuery() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:272
[0x0000000802a25c10] getThumbUrl() /srv/mediawiki/includes/filerepo/ForeignAPIRepo.php:342
[0x0000000802a25370] getThumbUrlFromCache() /srv/mediawiki/includes/filerepo/file/ForeignAPIFile.php:136
[0x0000000802a25110] transform() /srv/mediawiki/includes/Linker.php:668
[0x0000000802a24da0] processResponsiveImages() /srv/mediawiki/includes/Linker.php:441
[0x0000000802a24350] makeImageLink() /srv/mediawiki/includes/parser/Parser.php:5367
[0x0000000802a236c0] makeImage() /srv/mediawiki/includes/parser/Parser.php:2342

Current foreign repository added by the InstantCommons feature is:

>>> $wgForeignFileRepos
=> [
     [
       "class" => "ForeignAPIRepo",
       "name" => "wikimediacommons",
       "apibase" => "https://commons.wikimedia.org/w/api.php",
       "url" => "https://upload.wikimedia.org/wikipedia/commons",
       "thumbUrl" => "https://upload.wikimedia.org/wikipedia/commons/thumb",
       "hashLevels" => 2,
       "transformVia404" => true,
       "fetchDescription" => true,
       "descriptionCacheExpiry" => 43200,
       "apiThumbCacheExpiry" => 0,
       "directory" => (takes the $wgUploadDirectory value)
       "backend" => "wikimediacommons-backend",
     ],
   ]

Event Timeline

This should probably not be done. I think it would decrease performance by at least 50% on a cache miss (and change nothing on a cache hit). Disabling the cache disables the feature entirely which is a lot faster than simply caching it.

Tgr added a subscriber: Tgr.

According https://www.mediawiki.org/wiki/InstantCommons, InstantCommons requests are only fired once and cached on the server.

But on https://www.mediawiki.org/wiki/Manual:$wgUseInstantCommons, we can read "Since MediaWiki 1.27, $wgUseInstantCommons hotlinks images from Commons by default instead of downloading originals and thumbnailing them locally.".

The latter of those is accurate (with the default configuration). Image dimensions still need to be fetched for rendering the page HTML, though. They are already cached (descriptionCacheExpiry defaults to 12 hours) so I don't think there's anything actionable here.