mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
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:
parent
ebe04bb856
commit
139b5b879a
|
@ -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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue