r46835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46834‎ | r46835 | r46836 >
Date:06:41, 5 February 2009
Author:aaron
Status:deferred
Tags:
Comment:
Visually avoid cache/slave lag for rating table on review
Modified paths:
  • /trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/ReaderFeedback_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -623,7 +623,7 @@
624624 return $html;
625625 }
626626
627 - public static function getVoteAggregates( $page, $period ) {
 627+ public static function getVoteAggregates( $page, $period, $add = array() ) {
628628 global $wgLang, $wgMemc;
629629 if( $period > 93 ) {
630630 return ''; // too big
@@ -681,6 +681,12 @@
682682 }
683683 }
684684 }
 685+ // Tack on $add for display (used to avoid cache/lag)
 686+ foreach( $add as $tag => $val ) {
 687+ if( isset($votes[$tag]) && isset($votes[$tag][$val]) ) {
 688+ $votes[$tag][$val]++;
 689+ }
 690+ }
685691 $wgMemc->set( $key, array( $votes, $now ), 24*3600 );
686692 }
687693 // Output multi-column list
@@ -688,8 +694,13 @@
689695 foreach( FlaggedRevs::getFeedbackTags() as $tag => $w ) {
690696 // Get tag average...
691697 $dist = isset($votes[$tag]) ? $votes[$tag] : array();
692 - $ave = ($dist[0] + 2*$dist[1] + 3*$dist[2] + 4*$dist[3] + 5*$dist[4])/array_sum($dist);
693 - $ave = round($ave,1);
 698+ $count = array_sum($dist);
 699+ if( $count ) {
 700+ $ave = ($dist[0] + 2*$dist[1] + 3*$dist[2] + 4*$dist[3] + 5*$dist[4])/$count;
 701+ $ave = round($ave,1);
 702+ } else {
 703+ $ave = '-'; // DIV by zero
 704+ }
694705 $html .= '<td align="center"><b>'.wfMsgHtml("readerfeedback-$tag").'</b>&nbsp;&nbsp;'.
695706 '<sup>('.wfMsgHtml('ratinghistory-ave',$wgLang->formatNum($ave)).')</sup></td>';
696707 }
Index: trunk/extensions/FlaggedRevs/specialpages/ReaderFeedback_body.php
@@ -165,7 +165,7 @@
166166 $talk = $form->page->getTalkPage();
167167
168168 wfLoadExtensionMessages( 'RatingHistory' );
169 - $tallyTable = RatingHistory::getVoteAggregates( $form->page, 31 );
 169+ $tallyTable = RatingHistory::getVoteAggregates( $form->page, 31, $form->dims );
170170
171171 $dbw = wfGetDB( DB_MASTER );
172172 $dbw->begin();

Status & tagging log