r109979 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109978‎ | r109979 | r109980 >
Date:01:21, 25 January 2012
Author:gregchiasson
Status:ok (Comments)
Tags:aft 
Comment:
Make the helpful/unhelpful counts update on clicking one of the buttons. This pulls from the slave/read DB, in the interest of not hitting the master/write DB, which means the information it pulls might not be 100% up to date, but it seemed better than allowing selects on the master. I can fix that, if this is a problem. Update the javascript to support same.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -208,6 +208,11 @@
209209 if ( 'result' in data['articlefeedbackv5-flag-feedback'] ) {
210210 if( data['articlefeedbackv5-flag-feedback'].result == 'Success' ) {
211211 msg = 'articlefeedbackv5-' + type + '-saved';
 212+ if( 'helpful' in data['articlefeedbackv5-flag-feedback'] ) {
 213+
 214+ $( '#articleFeedbackv5-helpful-votes-' + id ).text( data['articlefeedbackv5-flag-feedback'].helpful );
 215+
 216+ }
212217 } else if (data['articlefeedbackv5-flag-feedback'].result == 'Error' ) {
213218 msg = data['articlefeedbackv5-flag-feedback'].reason;
214219 }
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -27,6 +27,7 @@
2828 $error = null;
2929 $dbr = wfGetDB( DB_SLAVE );
3030 $counts = array( 'increment' => array(), 'decrement' => array() );
 31+ $helpful = null;
3132
3233 # load feedback record, bail if we don't have one
3334 $record = $dbr->selectRow(
@@ -120,6 +121,30 @@
121122
122123 ApiArticleFeedbackv5Utils::incrementFilterCounts( $pageId, $counts['increment'] );
123124 ApiArticleFeedbackv5Utils::decrementFilterCounts( $pageId, $counts['decrement'] );
 125+
 126+ // This gets a potentially stale copy from the read
 127+ // database assumes it's valid, in the interest
 128+ // of staying off of the write database.
 129+ // Better stale data than wail on the master, IMO,
 130+ // but I'm open to suggestion on that one.
 131+
 132+ // Update helpful/unhelpful count after submission
 133+ if( $params['flagtype'] == 'helpful' || $params['flagtype'] == 'unhelpful' ) {
 134+ $record = $dbr->selectRow(
 135+ 'aft_article_feedback',
 136+ array( 'af_helpful_count', 'af_unhelpful_count' ),
 137+ array( 'af_id' => $params['feedbackid'] ),
 138+ __METHOD__
 139+ );
 140+
 141+ $helpful = $record->af_helpful_count;
 142+ $unhelpful = $record->af_unhelpful_count;
 143+
 144+ $helpful = wfMessage( 'articlefeedbackv5-form-helpful-votes',
 145+ ( $helpful + $unhelpful ),
 146+ $helpful, $unhelpful
 147+ )->escaped();
 148+ }
124149 }
125150
126151 if ( $error ) {
@@ -130,13 +155,19 @@
131156 $reason = null;
132157 }
133158
 159+ $results = array(
 160+ 'result' => $result,
 161+ 'reason' => $reason,
 162+ );
 163+
 164+ if( $helpful ) {
 165+ $results['helpful'] = $helpful;
 166+ }
 167+
134168 $this->getResult()->addValue(
135169 null,
136170 $this->getModuleName(),
137 - array(
138 - 'result' => $result,
139 - 'reason' => $reason,
140 - )
 171+ $results
141172 );
142173 }
143174
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -344,7 +344,8 @@
345345 ), wfMessage( 'articlefeedbackv5-form-helpful-no-label', $record[0]->af_unhelpful_count )->text() );
346346 }
347347 $footer_links .= Html::element( 'span', array(
348 - 'class' => 'articleFeedbackv5-helpful-votes'
 348+ 'class' => 'articleFeedbackv5-helpful-votes',
 349+ 'id' => "articleFeedbackv5-helpful-votes-$id"
349350 ), wfMessage( 'articlefeedbackv5-form-helpful-votes', ( $record[0]->af_helpful_count + $record[0]->af_unhelpful_count ), $record[0]->af_helpful_count, $record[0]->af_unhelpful_count ) );
350351 if( $can_flag ) {
351352 $footer_links .= Html::element( 'a', array(

Comments

#Comment by Catrope (talk | contribs)   07:28, 31 January 2012

Reading stale data from the slave is fine, as long as you don't use it to make decisions.

Status & tagging log