r41699 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41698‎ | r41699 | r41700 >
Date:18:11, 5 October 2008
Author:aaron
Status:old
Tags:
Comment:
* Tweak diff cache usage
* Minor diff query fix and refactoring to make it less cryptic
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -945,13 +945,9 @@
946946 # Try the sync value cache...
947947 $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $article->getId() );
948948 $value = FlaggedRevs::getMemcValue( $wgMemc->get($key), $article );
949 - if( $value === "true" ) {
950 - $synced = true;
951 - } else {
952 - $synced = false; // default as false to trigger query
953 - }
 949+ $synced = ($value === "true") ? true : false; // default as false to trigger query
954950 $frev = $this->getStableRev();
955 - if( $frev && $frev->getRevId() == $oldRev->getID() && !$synced ) {
 951+ if( $frev && $frev->getRevId() == $oldRev->getID() ) {
956952 global $wgParserCacheExpireTime, $wgUseStableTemplates, $wgUseStableImages;
957953
958954 $changeList = array();
@@ -960,6 +956,9 @@
961957 # Try the cache. Uses format <page ID>-<UNIX timestamp>.
962958 $key = wfMemcKey( 'stableDiffs', 'templates', (bool)$wgUseStableTemplates, $article->getId() );
963959 $tmpChanges = FlaggedRevs::getMemcValue( $wgMemc->get($key), $article );
 960+ if( empty($tmpChanges) && !$synced ) {
 961+ $tmpChanges = false; // don't use cache
 962+ }
964963
965964 # Make a list of each changed template...
966965 if( $tmpChanges === false ) {
@@ -967,14 +966,10 @@
968967 // Get templates where the current and stable are not the same revision
969968 if( $wgUseStableTemplates ) {
970969 $ret = $dbr->select( array('flaggedtemplates','page','flaggedpages'),
971 - array( 'ft_namespace', 'ft_title', 'fp_stable','ft_tmp_rev_id' ),
 970+ array( 'ft_namespace', 'ft_title', 'fp_stable','ft_tmp_rev_id', 'page_latest' ),
972971 array( 'ft_rev_id' => $frev->getRevId(),
973972 'page_namespace = ft_namespace',
974 - 'page_title = ft_title',
975 - // If the page has a stable version, is it current?
976 - // If not, is the specified one at review time current?
977 - '(fp_stable IS NOT NULL AND fp_stable != page_latest) OR
978 - (fp_stable IS NULL AND ft_tmp_rev_id != page_latest)' ),
 973+ 'page_title = ft_title' ),
979974 __METHOD__,
980975 array(), /* OPTIONS */
981976 array( 'flaggedpages' => array('LEFT JOIN','fp_page_id = page_id') )
@@ -982,7 +977,7 @@
983978 // Get templates that are newer than the ones of the stable version of this page
984979 } else {
985980 $ret = $dbr->select( array('flaggedtemplates','page'),
986 - array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id' ),
 981+ array( 'ft_namespace', 'ft_title', 'ft_tmp_rev_id', 'page_latest' ),
987982 array( 'ft_rev_id' => $frev->getRevId(),
988983 'page_namespace = ft_namespace',
989984 'page_title = ft_title',
@@ -992,9 +987,15 @@
993988 $tmpChanges = array();
994989 while( $row = $dbr->fetchObject( $ret ) ) {
995990 $title = Title::makeTitle( $row->ft_namespace, $row->ft_title );
996 - $revID = isset($row->fp_stable) ? $row->fp_stable : $row->ft_tmp_rev_id;
997 - $tmpChanges[] = $skin->makeKnownLinkObj( $title, $title->getPrefixedText(),
998 - "diff=cur&oldid={$revID}" );
 991+ $revIdDraft = $row->page_latest;
 992+ // stable time -> time when reviewed (unless the other is newer)
 993+ $revIdStable = isset($row->fp_stable) && $row->fp_stable >= $row->ft_tmp_rev_id ?
 994+ $row->fp_stable : $row->ft_tmp_rev_id;
 995+ // compare to current
 996+ if( $revIdDraft > $revIdStable ) {
 997+ $tmpChanges[] = $skin->makeKnownLinkObj( $title, $title->getPrefixedText(),
 998+ "diff=cur&oldid={$revID}" );
 999+ }
9991000 }
10001001 $wgMemc->set( $key, FlaggedRevs::makeMemcObj($tmpChanges), $wgParserCacheExpireTime );
10011002 }
@@ -1005,6 +1006,9 @@
10061007 # Try the cache. Uses format <page ID>-<UNIX timestamp>.
10071008 $key = wfMemcKey( 'stableDiffs', 'images', (bool)$wgUseStableImages, $article->getId() );
10081009 $imgChanges = FlaggedRevs::getMemcValue( $wgMemc->get($key), $article );
 1010+ if( empty($imgChanges) && !$synced ) {
 1011+ $imgChanges = false; // don't use cache
 1012+ }
10091013
10101014 // Get list of each changed image...
10111015 if( $imgChanges === false ) {
@@ -1031,11 +1035,11 @@
10321036 }
10331037 $imgChanges = array();
10341038 while( $row = $dbr->fetchObject( $ret ) ) {
 1039+ $title = Title::makeTitle( NS_IMAGE, $row->fi_name );
10351040 // stable time -> time when reviewed (unless the other is newer)
10361041 $timestamp = isset($row->fr_img_timestamp) && $row->fr_img_timestamp >= $row->fi_img_timestamp ?
10371042 $row->fr_img_timestamp : $row->fi_img_timestamp;
10381043 // compare to current
1039 - $title = Title::makeTitle( NS_IMAGE, $row->fi_name );
10401044 $file = wfFindFile( $title );
10411045 if( $file && $file->getTimestamp() > $timestamp )
10421046 $imgChanges[] = $skin->makeKnownLinkObj( $title, $title->getPrefixedText() );

Status & tagging log