r89196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89195‎ | r89196 | r89197 >
Date:01:06, 31 May 2011
Author:aaron
Status:ok
Tags:
Comment:
* Fixes for loop in getRevIncludes() from r88821
* Use $pOut->getCacheExpiry() for inclusion version cache expiry
* Minor refactoring
Modified paths:
  • /trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php
@@ -20,8 +20,7 @@
2121 global $wgParser, $wgMemc;
2222 wfProfileIn( __METHOD__ );
2323 $versions = false;
24 - $hash = md5( $article->getTitle()->getPrefixedDBkey() );
25 - $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $rev->getId(), $hash );
 24+ $key = self::getCacheKey( $article->getTitle(), $rev->getId() );
2625 if ( $regen !== 'regen' ) { // check cache
2726 $versions = FlaggedRevs::getMemcValue( $wgMemc->get( $key ), $article, 'allowStale' );
2827 }
@@ -48,13 +47,14 @@
4948 }
5049 # Get the template/file versions used...
5150 $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() );
52 - # Save to cache...
 51+ # Save to cache (check cache expiry for dynamic elements)...
5352 $data = FlaggedRevs::makeMemcObj( $versions );
54 - $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic
 53+ $wgMemc->set( $key, $data, $pOut->getCacheExpiry() );
5554 } else {
 55+ $tVersions =& $versions[0]; // templates
5656 # Do a link batch query for page_latest...
5757 $lb = new LinkBatch();
58 - foreach ( $versions as $ns => $tmps ) {
 58+ foreach ( $tVersions as $ns => $tmps ) {
5959 foreach ( $tmps as $dbKey => $revIdDraft ) {
6060 $lb->add( $ns, $dbKey );
6161 }
@@ -62,9 +62,9 @@
6363 $lb->execute();
6464 # Update array with the current page_latest values.
6565 # This kludge is there since $newTemplates (thus $revIdDraft) is cached.
66 - foreach ( $versions as $ns => $tmps ) {
 66+ foreach ( $tVersions as $ns => &$tmps ) {
6767 foreach ( $tmps as $dbKey => &$revIdDraft ) {
68 - $title = new Title( $ns, $dbKey );
 68+ $title = Title::makeTitle( $ns, $dbKey );
6969 $revIdDraft = (int)$title->getLatestRevID();
7070 }
7171 }
@@ -82,12 +82,16 @@
8383 */
8484 public static function setRevIncludes( Title $title, $revId, ParserOutput $pOut ) {
8585 global $wgMemc;
86 - $hash = md5( $title->getPrefixedDBkey() );
87 - $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $revId, $hash );
 86+ $key = self::getCacheKey( $title, $revId );
8887 # Get the template/file versions used...
8988 $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() );
90 - # Save to cache...
 89+ # Save to cache (check cache expiry for dynamic elements)...
9190 $data = FlaggedRevs::makeMemcObj( $versions );
92 - $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic
 91+ $wgMemc->set( $key, $data, $pOut->getCacheExpiry() );
9392 }
 93+
 94+ protected static function getCacheKey( Title $title, $revId ) {
 95+ $hash = md5( $title->getPrefixedDBkey() );
 96+ return wfMemcKey( 'flaggedrevs', 'revIncludes', $revId, $hash );
 97+ }
9498 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88821* Follow-up r88740:...aaron19:38, 25 May 2011

Status & tagging log