r36003 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36002‎ | r36003 | r36004 >
Date:19:33, 7 June 2008
Author:aaron
Status:old
Tags:
Comment:
Avoid extra query
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -486,26 +486,20 @@
487487 */
488488 public static function getRevCountSince( $article, $revId, $forUpdate=false ) {
489489 global $wgMemc;
490 - # Check if the count is zero by using $article->getLatest().
491 - # I don't trust using memcache and PHP for values like '0'
492 - # as it may confuse "expired" with "0".
493 - $latest = $forUpdate ? $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) : $article->getLatest();
494 - if( $latest == $revId ) {
495 - return 0;
496 - }
497490 # Try the cache
498491 $count = null;
499492 $key = wfMemcKey( 'flaggedrevs', 'unreviewedrevs', $article->getId() );
500493 if( !$forUpdate ) {
501 - $count = intval($wgMemc->get($key));
 494+ $val = $wgMemc->get($key);
 495+ $count = is_integer($val) ? $val : null;
502496 }
503 - if( !$count ) {
 497+ if( is_null($count) ) {
504498 $db = $forUpdate ? wfGetDB( DB_MASTER) : wfGetDB( DB_SLAVE );
505499 $count = $db->selectField( 'revision', 'COUNT(*)',
506500 array('rev_page' => $article->getId(), "rev_id > " . intval($revId) ),
507501 __METHOD__ );
508502 # Save to cache
509 - $wgMemc->set( $key, $count, 3600*24*7 );
 503+ $wgMemc->set( $key, intval($count), 3600*24*7 );
510504 }
511505 return $count;
512506 }

Status & tagging log