Extension:QuickInstantCommons

The QuickInstantCommons extension is a performance optimized version of $wgUseInstantCommons. It also allows basic thumbnailing of files that are missing a MediaHandler extension on the local wiki. For example, the first page of a PDF will still thumbnail even without Extension:PDFHandler installed, but advanced features like multipage requires the extension to be installed locally.

Initial testing was done using the page https://en.wikipedia.org/w/index.php?title=List_of_governors_general_of_Canada&oldid=1054426240 which has 85 images. Testing was done with caching disabled and an estimated TTFB for the api on an already setup connection of ~250ms.

It took 1038.18 with MediaWiki core's instant commons, 18.5 seconds with this extension with prefetching disabled, and 1.1 seconds with this extension but with prefetching enabled.

Configuration parameters
If you were previously using $wgUseInstantCommons, no configuration is needed beyond wfLoadExtension-ing this extension.


 * $wgUseQuickInstantCommons: Automatically setup $wgForeignFileRepos to use this extension (defaults true). Set to false if you need to customize something. You may need to set this before the wfLoadExtension line.
 * $wgQuickInstantCommonsPrefetch: Enable prefetching images based on what's in DB (Default true). Most of the time this is a major performance boost, but its possible that occasionally this might cause work to be done that isn't necessary.
 * $wgQuickInstantCommonsPrefetchMaxLimit: Max number of images to prefetch if prefetching is enabled (Default: 1000). Could hit OOM issues if too high.

Advanced Config
You can directly configure $wgForeignFileRepos if you want. For example, if you want to use this extension with a wiki that is not commons. Example:

apiMetadataExpiry is probably the most important value from a performance perspective (other then $wgQuickInstantCommonsPrefetch). If you feel things are slow, try increasing it. If a new version of a file is uploaded, it might not show up properly until after metadata expires. However you can force an expiry by purging the file description page on the local wiki.

Note: Unlike MediaWiki core's ForeignAPIRepo, $wgResponsiveImages should not impact performance, so it is recommended that you keep it turned on.

Differences between this and ForeignApiFileRepo

 * Caches curl handle
 * Uses HTTP/2 multiplexing (Major performance boost)
 * ?action=purge of File pages purges image metadata
 * Does not support local thumbnail caching
 * Automatically generate thumbnail urls locally if foreign repo supports 404 handling (Major performance boost. Especially when responsive images are enabled)
 * Prefetch expected images based on imagelinks table (Major performance boost)
 * Allows limited thumbnailing of files that are missing handler extension (e.g. Still show thumbnail of first page of a PDF even if you don't have Extension:PDFHandler installed).
 * Adaptive TTL support that actually works (If the foreign image was recently edited, cache for shorter time, so that if its vandalism the revert will show up faster).
 * Configurable metadata caching time, with better defaults than core.

Other ideas that haven't been implemented: better adaptive cache for image description pages.