r39062 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39061‎ | r39062 | r39063 >
Date:10:30, 10 August 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Whitespace fixes
* Avoid running some queries multiple times by caching the result
- Title::isDeleted is called twice when viewing a page that does not exist by SkinTemplate::buildContentActionUrls and Skin::getUndeleteLink
- Title::getTitleProtections is called twice when viewing a page that does not exist by SkinTemplate::buildContentActionUrls and efUniversalEditLink
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -45,28 +45,29 @@
4646 * @private
4747 */
4848
49 - var $mTextform = ''; # Text form (spaces not underscores) of the main part
50 - var $mUrlform = ''; # URL-encoded form of the main part
51 - var $mDbkeyform = ''; # Main part with underscores
 49+ var $mTextform = ''; # Text form (spaces not underscores) of the main part
 50+ var $mUrlform = ''; # URL-encoded form of the main part
 51+ var $mDbkeyform = ''; # Main part with underscores
5252 var $mUserCaseDBKey; # DB key with the initial letter in the case specified by the user
5353 var $mNamespace = NS_MAIN; # Namespace index, i.e. one of the NS_xxxx constants
54 - var $mInterwiki = ''; # Interwiki prefix (or null string)
55 - var $mFragment; # Title fragment (i.e. the bit after the #)
 54+ var $mInterwiki = ''; # Interwiki prefix (or null string)
 55+ var $mFragment; # Title fragment (i.e. the bit after the #)
5656 var $mArticleID = -1; # Article ID, fetched from the link cache on demand
5757 var $mLatestID = false; # ID of most recent revision
5858 var $mRestrictions = array(); # Array of groups allowed to edit this article
5959 var $mOldRestrictions = false;
60 - var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
61 - var $mRestrictionsExpiry; # When do the restrictions on this page expire?
 60+ var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
 61+ var $mRestrictionsExpiry; # When do the restrictions on this page expire?
6262 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
6363 var $mCascadeRestrictionSources; # Where are the cascading restrictions coming from on this page?
6464 var $mRestrictionsLoaded = false; # Boolean for initialisation on demand
65 - var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
 65+ var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
 66+
6667 # Don't change the following default, NS_MAIN is hardcoded in several
6768 # places. See bug 696.
6869 var $mDefaultNamespace = NS_MAIN; # Namespace index when there is no namespace
69 - # Zero except in {{transclusion}} tags
70 - var $mWatched = null; # Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
 70+ # Zero except in {{transclusion}} tags
 71+ var $mWatched = null; # Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
7172 var $mLength = -1; # The page length, 0 for special pages
7273 var $mRedirect = null; # Is the article at this title a redirect?
7374 /**#@-*/
@@ -1339,15 +1340,28 @@
13401341 return false;
13411342 }
13421343
 1344+ wfDebug( wfBacktrace() );
 1345+
 1346+ // Cache to avoid multiple database queries for the same title
 1347+ if ( isset($this->mProtections) ) {
 1348+ return $this->mProtections;
 1349+ }
 1350+
 1351+ $conds = array(
 1352+ 'pt_namespace' => $this->getNamespace(),
 1353+ 'pt_title' => $this->getDBkey()
 1354+ );
 1355+
13431356 $dbr = wfGetDB( DB_SLAVE );
1344 - $res = $dbr->select( 'protected_titles', '*',
1345 - array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
 1357+ $res = $dbr->select( 'protected_titles', '*', $conds, __METHOD__ );
13461358
13471359 if ($row = $dbr->fetchRow( $res )) {
1348 - return $row;
 1360+ $this->mProtections = $row;
13491361 } else {
1350 - return false;
 1362+ $this->mProtections = false;
13511363 }
 1364+
 1365+ return $this->mProtections;
13521366 }
13531367
13541368 public function updateTitleProtection( $create_perm, $reason, $expiry ) {
@@ -1879,19 +1893,30 @@
18801894 * @return int the number of archived revisions
18811895 */
18821896 public function isDeleted() {
1883 - $fname = 'Title::isDeleted';
18841897 if ( $this->getNamespace() < 0 ) {
1885 - $n = 0;
1886 - } else {
1887 - $dbr = wfGetDB( DB_SLAVE );
1888 - $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1889 - 'ar_title' => $this->getDBkey() ), $fname );
1890 - if( $this->getNamespace() == NS_IMAGE ) {
1891 - $n += $dbr->selectField( 'filearchive', 'COUNT(*)',
1892 - array( 'fa_name' => $this->getDBkey() ), $fname );
1893 - }
 1898+ return 0;
18941899 }
1895 - return (int)$n;
 1900+
 1901+ // Cache to avoid multiple queries for the same title
 1902+ if ( isset($this->mIsDeleted) ) {
 1903+ return $this->mIsDeleted;
 1904+ }
 1905+
 1906+ $dbr = wfGetDB( DB_SLAVE );
 1907+ $aConds = array(
 1908+ 'ar_namespace' => $this->getNamespace(),
 1909+ 'ar_title' => $this->getDBkey()
 1910+ );
 1911+ $n = $dbr->selectField( 'archive', 'COUNT(*)', $aConds, __METHOD__ );
 1912+
 1913+ if ( $this->getNamespace() == NS_IMAGE ) {
 1914+ $faConds = array( 'fa_name' => $this->getDBkey() );
 1915+ $n += $dbr->selectField( 'filearchive', 'COUNT(*)', $faConds , __METHOD__ );
 1916+ }
 1917+
 1918+ $this->mIsDeleted = (int) $n;
 1919+
 1920+ return $this->mIsDeleted;
18961921 }
18971922
18981923 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r39084Revert r39062 "Avoid running some queries multiple times by caching the result"...brion20:34, 10 August 2008

Status & tagging log