cache the result of getTitleProtection to make testing easier
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 24 Apr 2010 00:23:57 +0000 (00:23 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 24 Apr 2010 00:23:57 +0000 (00:23 +0000)
includes/Title.php

index d68950f..3b9d220 100644 (file)
@@ -63,6 +63,7 @@ class Title {
        var $mCascadeSources;             ///< Where are the cascading restrictions coming from on this page?
        var $mRestrictionsLoaded = false; ///< Boolean for initialisation on demand
        var $mPrefixedText;               ///< Text form including namespace/interwiki, initialised on demand
+       var $mTitleProtection;            ///< Cached value of getTitleProtection
        # Don't change the following default, NS_MAIN is hardcoded in several
        # places.  See bug 696.
        var $mDefaultNamespace = NS_MAIN; ///< Namespace index when there is no namespace
@@ -1481,16 +1482,16 @@ class Title {
                        return false;
                }
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'protected_titles', '*',
-                       array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
-                       __METHOD__ );
+               if ( !isset( $this->mTitleProtection ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $res = $dbr->select( 'protected_titles', '*',
+                               array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
+                               __METHOD__ );
 
-               if ($row = $dbr->fetchRow( $res )) {
-                       return $row;
-               } else {
-                       return false;
+                       // fetchRow returns false if there are no rows.
+                       $this->mTitleProtection = $dbr->fetchRow( $res );
                }
+               return $this->mTitleProtection;
        }
 
        /**