r105764 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105763‎ | r105764 | r105765 >
Date:16:30, 10 December 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Added revision's timestamp to OutputPage along with revision ID; avoid a DB hit in Skin::lastModified() when showing parser cache's content. This changed with the removal of $wgArticle in Skin since now it's a different WikiPage object and thus WikiPage::setTimetstamp() call is useless (but still kept).
* Added ParserOutput::(get|set)Timestamp() and the $mTimestamp member; avoid messing with isset()
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserCache.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -499,6 +499,7 @@
500500 if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
501501 $this->loadNewText();
502502 $out->setRevisionId( $this->mNewid );
 503+ $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
503504 $out->setArticleFlag( true );
504505
505506 if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
Index: trunk/phase3/includes/Article.php
@@ -497,11 +497,10 @@
498498 # Ensure that UI elements requiring revision ID have
499499 # the correct version information.
500500 $wgOut->setRevisionId( $this->mPage->getLatest() );
 501+ # Preload timestamp to avoid a DB hit
 502+ $wgOut->setRevisionTimestamp( $this->mParserOutput->getTimestamp() );
 503+ $this->mPage->setTimestamp( $this->mParserOutput->getTimestamp() );
501504 $outputDone = true;
502 - # Preload timestamp to avoid a DB hit
503 - if ( isset( $this->mParserOutput->mTimestamp ) ) {
504 - $this->mPage->setTimestamp( $this->mParserOutput->mTimestamp );
505 - }
506505 }
507506 }
508507 break;
@@ -523,6 +522,8 @@
524523 # Ensure that UI elements requiring revision ID have
525524 # the correct version information.
526525 $wgOut->setRevisionId( $this->getRevIdFetched() );
 526+ # Preload timestamp to avoid a DB hit
 527+ $wgOut->setRevisionTimestamp( $this->getTimestamp() );
527528
528529 # Pages containing custom CSS or JavaScript get special treatment
529530 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
Index: trunk/phase3/includes/parser/ParserOutput.php
@@ -138,8 +138,9 @@
139139 $mSections = array(), # Table of contents
140140 $mEditSectionTokens = false, # prefix/suffix markers if edit sections were output as tokens
141141 $mProperties = array(), # Name/value pairs to be cached in the DB
142 - $mTOCHTML = ''; # HTML of the TOC
143 - private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
 142+ $mTOCHTML = '', # HTML of the TOC
 143+ $mTimestamp; # Timestamp of the revision
 144+ private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
144145 private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys)
145146
146147 const EDITSECTION_REGEX = '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
@@ -205,6 +206,7 @@
206207 function getWarnings() { return array_keys( $this->mWarnings ); }
207208 function getIndexPolicy() { return $this->mIndexPolicy; }
208209 function getTOCHTML() { return $this->mTOCHTML; }
 210+ function getTimestamp() { return $this->mTimestamp; }
209211
210212 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
211213 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
@@ -215,6 +217,7 @@
216218 function setEditSectionTokens( $t ) { return wfSetVar( $this->mEditSectionTokens, $t ); }
217219 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
218220 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
 221+ function setTimestamp( $timestamp ) { return wfSetVar( $this->mTimestamp, $timestamp ); }
219222
220223 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
221224 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
Index: trunk/phase3/includes/parser/ParserCache.php
@@ -220,7 +220,7 @@
221221 $popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) );
222222
223223 // Save the timestamp so that we don't have to load the revision row on view
224 - $parserOutput->mTimestamp = $article->getTimestamp();
 224+ $parserOutput->setTimestamp( $article->getTimestamp() );
225225
226226 $parserOutput->mText .= "\n<!-- Saved in parser cache with key $parserOutputKey and timestamp $now -->\n";
227227 wfDebug( "Saved in parser cache with key $parserOutputKey and timestamp $now\n" );
Index: trunk/phase3/includes/OutputPage.php
@@ -197,6 +197,7 @@
198198
199199 /// should be private. To include the variable {{REVISIONID}}
200200 var $mRevisionId = null;
 201+ private $mRevisionTimestamp = null;
201202
202203 var $mFileVersion = null;
203204
@@ -1340,6 +1341,27 @@
13411342 }
13421343
13431344 /**
 1345+ * Set the timestamp of the revision which will be displayed. This is used
 1346+ * to avoid a extra DB call in Skin::lastModified().
 1347+ *
 1348+ * @param $revid Mixed: string, or null
 1349+ * @return Mixed: previous value
 1350+ */
 1351+ public function setRevisionTimestamp( $timestmap ) {
 1352+ return wfSetVar( $this->mRevisionTimestamp, $timestmap );
 1353+ }
 1354+
 1355+ /**
 1356+ * Get the timestamp of displayed revision.
 1357+ * This will be null if not filled by setRevisionTimestamp().
 1358+ *
 1359+ * @return String or null
 1360+ */
 1361+ public function getRevisionTimestamp() {
 1362+ return $this->mRevisionTimestamp;
 1363+ }
 1364+
 1365+ /**
13441366 * Set the displayed file version
13451367 *
13461368 * @param $file File|false
Index: trunk/phase3/includes/SkinTemplate.php
@@ -353,7 +353,7 @@
354354 if ( $wgMaxCredits != 0 ) {
355355 $tpl->set( 'credits', Action::factory( 'credits', $page, $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
356356 } else {
357 - $tpl->set( 'lastmod', $this->lastModified( $page ) );
 357+ $tpl->set( 'lastmod', $this->lastModified() );
358358 }
359359 }
360360 $tpl->set( 'copyright', $this->getCopyright() );
Index: trunk/phase3/includes/Skin.php
@@ -828,14 +828,14 @@
829829 /**
830830 * Get the timestamp of the latest revision, formatted in user language
831831 *
832 - * @param $page WikiPage object. Used if we're working with the current revision
833832 * @return String
834833 */
835 - protected function lastModified( $page ) {
836 - if ( !$this->isRevisionCurrent() ) {
 834+ protected function lastModified() {
 835+ $timestamp = $this->getOutput()->getRevisionTimestamp();
 836+
 837+ # No cached timestamp, load it from the database
 838+ if ( $timestamp === null ) {
837839 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
838 - } else {
839 - $timestamp = $page->getTimestamp();
840840 }
841841
842842 if ( $timestamp ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r106476Per Aaron, fix for r105764: only set the timestamp if it's set in the cached ...ialex20:55, 16 December 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   17:14, 10 December 2011

Can you kill setTimestamp from wikipage if no one needs it now?

#Comment by IAlex (talk | contribs)   19:40, 10 December 2011

I left the call to setTimestamp() from ParserCache hit since I'm not sure if something still uses getTimestamp().

#Comment by Aaron Schulz (talk | contribs)   00:44, 14 December 2011

So Skin and OutputPage have different Page instances? Isn't that a performance regression. It's ok to allow it, but it shouldn't happen on actual page views in practice.

#Comment by IAlex (talk | contribs)   19:34, 16 December 2011

Basically after this rev and r105790, this shouldn't have performance regression for normal page views (except maybe when $wgMaxCredits is > 0).

#Comment by Aaron Schulz (talk | contribs)   19:47, 16 December 2011
+$this->mPage->setTimestamp( $this->mParserOutput->getTimestamp() );

Are you sure that you will never be setting it to null (and thus causing an extra query)? ParserOutput->getTimestamp() isn't assured to return a timestamp.

#Comment by IAlex (talk | contribs)   20:58, 16 December 2011

Done in r106476.

Status & tagging log