Pre-existing performance issue, discovered during review of https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1172700 for T393835: Explore removing WikiModuleTitleInfo in ResourceLoader, in favour of standard LinkCache.
On every page view, WikiModule performs two separate database queries instead of one, despite having apparent preloading and batching logic. The first query is the bigger one and originates from the preloader. The second one coveres only one module/page. I suspect the preload in OutputPage has incomplete search critera for its batch, thus not covering the second call in production.
Note that this is not an issue by default in MediaWiki core. The preloader covers all default scenarios in MediaWiki core. The second database query appears specifically when the GlobalCssJs extension is installed, in a more production-like setup (wiki farm with a central wiki).
Example:
- Quickstart + Wiki farm on MySQL
- Wikis: centralwiki, foowiki
- Config: Database-based session store (so that you can restart the server and stay logged-in). APCU-based cache (so that you can easily clear the MW maincache by simply restarting composer-serve).
- $wgMainCacheType = CACHE_ACCEL; $wgSessionCacheType = CACHE_DB; $wgDebugToolbar = true;
- GlobalCssJs installed with prod-like config.
- On centralwiki, User:Admin/global.css exists. User:Admin/global.js does not.
- Viewing foowiki, logged-in as admin.
- Restart (stay logged-in, clear MW maincache).
- Hard reload (cold, cache miss) — This performs two database queries to centralwiki from WikiModule instead of one.
- Hard reload (warm, cache hit) — Idem, two instead of one.
$wgAllowUserCss = true; $wgAllowUserJs = true; $wgUseGlobalSiteCssJs = false; if ( KRINKLE_WIKIFARM ) { $wgResourceLoaderSources['centralwiki'] = [ 'apiScript' => 'http://central.localhost:4000/api.php', 'loadScript' => 'http://central.localhost:4000/load.php', ]; $wgGlobalCssJsConfig['wiki'] = 'centralwiki'; $wgGlobalCssJsConfig['source'] = 'centralwiki'; }
USE centralwiki; SELECT page_namespace,page_title,page_touched,page_len,page_latest FROM page WHERE ((page_namespace = 2 AND page_title = 'Admin/global.css')) USE centralwiki; centralwiki SELECT page_namespace,page_title,page_touched,page_len,page_latest FROM page WHERE ((page_namespace = 2 AND page_title = 'Admin/global.js'))