perf(sections): ️ re-order conditions to short circuit earlier

We should not call MediaWikiServices first every time for formatting sections.
Instead it should be done last as other checks are cheaper.
This commit is contained in:
alistair3149 2024-10-23 15:14:18 -04:00
parent 18ad833bce
commit 01419e7619
No known key found for this signature in database

View file

@ -60,23 +60,27 @@ final class BodyContent extends Partial {
* @return bool
*/
private function shouldFormatPage( $title ) {
$shouldFormat = (
$this->getConfigValue( 'CitizenEnableCollapsibleSections' ) === true &&
$title->canExist() &&
!$title->isMainPage() &&
$title->isContentPage() &&
$title->getContentModel() === CONTENT_MODEL_WIKITEXT
);
if ( !$shouldFormat ) {
return false;
}
// Check if page is in mobile view and let MF do the formatting
try {
$mfCxt = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
// Check if page is in mobile view and let MF do the formatting
return !$mfCxt->shouldDisplayMobileView();
} catch ( NoSuchServiceException $ex ) {
// MobileFrontend not installed. Don't do anything
}
$enableSections = (
$this->getConfigValue( 'CitizenEnableCollapsibleSections' ) === true &&
$title->canExist() &&
$title->getContentModel() == CONTENT_MODEL_WIKITEXT &&
!$title->isMainPage() &&
$title->isContentPage()
);
return $enableSections;
return true;
}
/**