DesktopArticleTargetInitModule: Avoid expensive $msg->exists check

This check currently requires LCStore, MessageCache, and (sometimes)
Database to involved to check whether the message and/or local override
exist.

Using `useDatabase(false)` should take away most of this cost
by no longer performing the multiple Memcached/Database roundtrips,
and leaving only a cheap in-process check on LCStore.

Bug: T221294
Change-Id: I6bf47cd84cdf9bfdd63bee0a613425bb79595e4f
This commit is contained in:
Timo Tijhof 2019-04-17 22:13:31 +01:00
parent ebe04bb856
commit 139b5b879a

View file

@ -24,13 +24,18 @@ class VisualEditorDesktopArticleTargetInitModule extends ResourceLoaderFileModul
array_filter( $veConfig->get( 'VisualEditorTabMessages' ) ) array_filter( $veConfig->get( 'VisualEditorTabMessages' ) )
); );
// Skin-dependent messages for the edit tab (same as generated by SkinTemplate). // Some skins don't use the default 'edit' and 'create' message keys.
// We only need the message for the current skin, but we don't know which skin will be used. // Check the localisation cache for which skins have a custom message for this.
// Only some skins use these (e.g. Vector), others just use default 'edit' and 'create'. // We only need this for the current skin, but ResourceLoader's message cache
// does not fragment by skin.
foreach ( SkinFactory::getDefaultInstance()->getSkinNames() as $skname => $unused ) { foreach ( SkinFactory::getDefaultInstance()->getSkinNames() as $skname => $unused ) {
foreach ( [ 'edit', 'create' ] as $msgKey ) { foreach ( [ 'edit', 'create' ] as $msgKey ) {
// e.g. vector-view-edit, vector-view-create // Messages: vector-view-edit, vector-view-create
if ( wfMessage( "$skname-view-$msgKey" )->inContentLanguage()->exists() ) { // Disable database lookups for site-level message overrides as they
// are expensive and not needed here (T221294). We only care whether the
// message key is known to localisation cache at all.
$msg = wfMessage( "$skname-view-$msgKey" )->useDatabase( false )->inContentLanguage();
if ( $msg->exists() ) {
$messages[] = "$skname-view-$msgKey"; $messages[] = "$skname-view-$msgKey";
} }
} }