r39084 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39083‎ | r39084 | r39085 >
Date:20:34, 10 August 2008
Author:brion
Status:old
Tags:
Comment:
Revert r39062 "Avoid running some queries multiple times by caching the result"
This complicates the code with extra internal caching for extremely rare cases (a couple extra queries on non-existent pages).
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -45,29 +45,28 @@
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
66 -
 65+ var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
6766 # Don't change the following default, NS_MAIN is hardcoded in several
6867 # places. See bug 696.
6968 var $mDefaultNamespace = NS_MAIN; # Namespace index when there is no namespace
70 - # Zero except in {{transclusion}} tags
71 - var $mWatched = null; # Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
 69+ # Zero except in {{transclusion}} tags
 70+ var $mWatched = null; # Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
7271 var $mLength = -1; # The page length, 0 for special pages
7372 var $mRedirect = null; # Is the article at this title a redirect?
7473 /**#@-*/
@@ -1340,26 +1339,15 @@
13411340 return false;
13421341 }
13431342
1344 - // Cache to avoid multiple database queries for the same title
1345 - if ( isset($this->mProtections) ) {
1346 - return $this->mProtections;
1347 - }
1348 -
1349 - $conds = array(
1350 - 'pt_namespace' => $this->getNamespace(),
1351 - 'pt_title' => $this->getDBkey()
1352 - );
1353 -
13541343 $dbr = wfGetDB( DB_SLAVE );
1355 - $res = $dbr->select( 'protected_titles', '*', $conds, __METHOD__ );
 1344+ $res = $dbr->select( 'protected_titles', '*',
 1345+ array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
13561346
13571347 if ($row = $dbr->fetchRow( $res )) {
1358 - $this->mProtections = $row;
 1348+ return $row;
13591349 } else {
1360 - $this->mProtections = false;
 1350+ return false;
13611351 }
1362 -
1363 - return $this->mProtections;
13641352 }
13651353
13661354 public function updateTitleProtection( $create_perm, $reason, $expiry ) {
@@ -1891,30 +1879,19 @@
18921880 * @return int the number of archived revisions
18931881 */
18941882 public function isDeleted() {
 1883+ $fname = 'Title::isDeleted';
18951884 if ( $this->getNamespace() < 0 ) {
1896 - return 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+ }
18971894 }
1898 -
1899 - // Cache to avoid multiple queries for the same title
1900 - if ( isset($this->mIsDeleted) ) {
1901 - return $this->mIsDeleted;
1902 - }
1903 -
1904 - $dbr = wfGetDB( DB_SLAVE );
1905 - $aConds = array(
1906 - 'ar_namespace' => $this->getNamespace(),
1907 - 'ar_title' => $this->getDBkey()
1908 - );
1909 - $n = $dbr->selectField( 'archive', 'COUNT(*)', $aConds, __METHOD__ );
1910 -
1911 - if ( $this->getNamespace() == NS_IMAGE ) {
1912 - $faConds = array( 'fa_name' => $this->getDBkey() );
1913 - $n += $dbr->selectField( 'filearchive', 'COUNT(*)', $faConds , __METHOD__ );
1914 - }
1915 -
1916 - $this->mIsDeleted = (int) $n;
1917 -
1918 - return $this->mIsDeleted;
 1895+ return (int)$n;
19191896 }
19201897
19211898 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39062* Whitespace fixes...nikerabbit10:30, 10 August 2008

Status & tagging log