jenkins-bot has submitted this change and it was merged.

Change subject: Cache page content language in Title object
......................................................................


Cache page content language in Title object

During the parsing process, $title->getPageLanguage() gets called
a large number of times for the same title. Apparently the value
can vary by user, but it should be safe to cache for the current
request (I believe).

On [[Commons:Commons:Featured_picture_candidates/Log/October_2013]],
it appears that this method is called 5118 times, and represents
20.58% (11.77 seconds) of the time to render the page.

Also checks if $wgLanguageCode has been changed, since Title
object are cached during a request, and the unit tests seem
to change $wgLanguageCode/$wgContLang while still using
the Title cache.

Bug: 55952
Change-Id: I84b2d86c7bcb32997acff47cfea0f789b5b960a6
---
M includes/Title.php
1 file changed, 17 insertions(+), 7 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Title.php b/includes/Title.php
index 56e9b44..3418fa2 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -86,6 +86,7 @@
        var $mRedirect = null;            // /< Is the article at this title a 
redirect?
        var $mNotificationTimestamp = array(); // /< Associative array of user 
ID -> timestamp/false
        var $mHasSubpage;                 // /< Whether a page has any subpages
+       private $mPageLanguage = false;   // /< The (string) language code of 
the page's language and content code.
        // @}
 
        /**
@@ -3110,6 +3111,7 @@
                $this->mLatestID = false;
                $this->mContentModel = false;
                $this->mEstimateRevisions = null;
+               $this->mPageLanguage = false;
        }
 
        /**
@@ -4808,18 +4810,26 @@
         * @return Language
         */
        public function getPageLanguage() {
-               global $wgLang;
+               global $wgLang, $wgLanguageCode;
+               wfProfileIn( __METHOD__ );
                if ( $this->isSpecialPage() ) {
                        // special pages are in the user language
+                       wfProfileOut( __METHOD__ );
                        return $wgLang;
                }
 
-               //TODO: use the LinkCache to cache this! Note that this may 
depend on user settings, so the cache should be only per-request.
-               //NOTE: ContentHandler::getPageLanguage() may need to load the 
content to determine the page language!
-               $contentHandler = ContentHandler::getForTitle( $this );
-               $pageLang = $contentHandler->getPageLanguage( $this );
-
-               return wfGetLangObj( $pageLang );
+               if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== 
$wgLanguageCode ) {
+                       // Note that this may depend on user settings, so the 
cache should be only per-request.
+                       // NOTE: ContentHandler::getPageLanguage() may need to 
load the content to determine the page language!
+                       // Checking $wgLanguageCode hasn't changed for the 
benefit of unit tests.
+                       $contentHandler = ContentHandler::getForTitle( $this );
+                       $langObj = wfGetLangObj( 
$contentHandler->getPageLanguage( $this ) );
+                       $this->mPageLanguage = array( $langObj->getCode(), 
$wgLanguageCode );
+               } else {
+                       $langObj =  wfGetLangObj( $this->mPageLanguage[0] );
+               }
+               wfProfileOut( __METHOD__ );
+               return $langObj;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/90769
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I84b2d86c7bcb32997acff47cfea0f789b5b960a6
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: SPQRobin <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to