r105460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105459‎ | r105460 | r105461 >
Date:21:14, 7 December 2011
Author:gregchiasson
Status:ok (Comments)
Tags:
Comment:
AFTv5 - adding indices to tables, removing unused anontoken param, caching revisionLimit call in API, add comments.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
@@ -147,7 +147,10 @@
148148 PRIMARY KEY (afp_feedback_id, afp_key)
149149 ) /*$wgDBTableOptions*/;
150150
 151+-- TODO: Add indicesafi_data_type);
 152+CREATE INDEX /*i*/af_page_revision ON /*_*/aft_article_feedback (af_page_id, af_revision_id);
 153+CREATE INDEX /*i*/afi_data_type ON /*_*/aft_article_field (afi_data_type);
 154+CREATE INDEX /*i*/aa_feedback_field_option ON /*_*/aft_article_answer (aa_feedback_id, aa_field_id, aa_response_option_id);
151155
152156 INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES ('found', 'boolean', 1);
153157 INSERT INTO aft_article_field(afi_name, afi_data_type, afi_bucket_id) VALUES ('comment', 'text', 1);
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -2205,7 +2205,6 @@
22062206 var data = $.extend( formdata, {
22072207 'action': 'articlefeedbackv5',
22082208 'format': 'json',
2209 - 'anontoken': $.articleFeedbackv5.userId,
22102209 'pageid': $.articleFeedbackv5.pageId,
22112210 'revid': $.articleFeedbackv5.revisionId,
22122211 'bucket': $.articleFeedbackv5.bucketId,
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -16,6 +16,8 @@
1717 * @subpackage Api
1818 */
1919 class ApiArticleFeedbackv5 extends ApiBase {
 20+ // Cache this, so we don't have to look it up every time.
 21+ private $revision_limit = null;
2022
2123 /**
2224 * Constructor
@@ -44,14 +46,15 @@
4547 $pageId = $params['pageid'];
4648 $bucket = $params['bucket'];
4749 $revisionId = $params['revid'];
 50+ $error = null;
 51+ $user_answers = array();
 52+ $fields = ApiArticleFeedbackv5Utils::getFields();
4853 $email_data = array(
4954 'ratingData' => array(),
5055 'pageID' => $pageId,
5156 'bucketId' => $bucket
5257 );
5358
54 - $user_answers = array();
55 - $fields = ApiArticleFeedbackv5Utils::getFields();
5659 foreach ( $fields as $field ) {
5760 if ( $field->afi_bucket_id != $bucket ) {
5861 continue;
@@ -73,11 +76,18 @@
7477 $user_answers[] = $data;
7578 $email_data['ratingData'][$field->afi_name] = $value;
7679 } else {
77 - // TODO: ERROR
 80+ $error = 'articlefeedbackv5-error-validation';
7881 }
7982 }
8083 }
8184
 85+ if($error) {
 86+ $this->getResult()->addValue(
 87+ null, 'error', $error
 88+ );
 89+ return;
 90+ }
 91+
8292 $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket );
8393 $this->updateRollupTables( $pageId, $revisionId );
8494
@@ -91,10 +101,8 @@
92102 wfAppendQuery( wfScript( 'api' ), array(
93103 'action' => 'query',
94104 'format' => 'json',
95 - 'list' => 'articlefeedback',
 105+ 'list' => 'articlefeedbackv5-view-ratings',
96106 'afpageid' => $pageId,
97 - 'afanontoken' => '',
98 - 'afuserrating' => 0,
99107 'maxage' => 0,
100108 'smaxage' => $wgArticleFeedbackv5SMaxage
101109 ) )
@@ -183,11 +191,34 @@
184192 }
185193
186194 /**
 195+ * Cache result of ApiArticleFeedbackv5Utils::getRevisionLimit to avoid
 196+ * multiple fetches.
 197+
 198+ * @param $pageID int the page id
 199+ * @return int the oldest revision to still count
 200+ */
 201+ public function getRevisionLimit( $pageId ) {
 202+ if( $this->revision_limit === null ) {
 203+ $this->revision_limit = ApiArticleFeedbackv5Utils::getRevisionLimit( $pageId );
 204+ }
 205+ return $this->revision_limit;
 206+ }
 207+
 208+ /**
187209 * Update the rollup tables
188210 *
189211 * @param $page int the page id
190212 * @param $revision int the revision id
191213 * @param $type string the type (rating, select, or boolean)
 214+
 215+ * Selects feedback across the last $wgArticleFeedbackv5RatingLifetime
 216+ * revisions of this page, grouped by revisionId. Each revision row
 217+ * is replaced, as well as the page-level one in that rollup, which is
 218+ * the sum of all revision-level rollups. We don't know if the revision
 219+ * window has changed, so every time we're checking for the relevent
 220+ * revisions and replacing the page value, as old revisions fall out of
 221+ * the window.
 222+
192223 */
193224 private function updateRollup( $pageId, $revId, $type ) {
194225 # sanity check
@@ -198,7 +229,7 @@
199230 global $wgArticleFeedbackv5RatingLifetime;
200231 $dbr = wfGetDB( DB_SLAVE );
201232 $dbw = wfGetDB( DB_MASTER );
202 - $limit = ApiArticleFeedbackv5Utils::getRevisionLimit( $pageId );
 233+ $limit = $this->getRevisionLimit( $pageId );
203234 $page_data = array();
204235 $rev_data = array();
205236 $rev_table = 'aft_article_revision_feedback_'
@@ -239,13 +270,17 @@
240271 $group
241272 );
242273
243 - # Fake the select counts, because we want to group by ughhh
 274+ // We've already grouped by option_id, so in order to get
 275+ // counts grouped by field_id, we need to sum them up here.
 276+ // Necessary for select rollups, unused on ratings/booleans.
244277 $totals = array();
245 - foreach ( $rows as $row ) {
246 - if( !array_key_exists( $row->aa_field_id, $totals ) ) {
247 - $totals[$row->aa_field_id] = 0;
 278+ if( $type == 'option_id' ) {
 279+ foreach ( $rows as $row ) {
 280+ if( !array_key_exists( $row->aa_field_id, $totals ) ) {
 281+ $totals[$row->aa_field_id] = 0;
 282+ }
 283+ $totals[$row->aa_field_id] += $row->earned;
248284 }
249 - $totals[$row->aa_field_id] += $row->earned;
250285 }
251286
252287 foreach ( $rows as $row ) {
@@ -415,7 +450,6 @@
416451 ApiBase::PARAM_TYPE => 'integer',
417452 ApiBase::PARAM_REQUIRED => true,
418453 ),
419 - 'anontoken' => null,
420454 'bucket' => array(
421455 ApiBase::PARAM_TYPE => 'integer',
422456 ApiBase::PARAM_REQUIRED => true,

Follow-up revisions

RevisionCommit summaryAuthorDate
r105495AFTv5 OK, turns out I was too hasty removing anontoken. Rolling back part of ...gregchiasson23:59, 7 December 2011

Comments

#Comment by Catrope (talk | contribs)   16:39, 12 December 2011
--- TODO: Add indices
+-- TODO: Add indicesafi_data_type);

lol?

+	public function getRevisionLimit( $pageId ) {

You should probably store the page ID in an object variable too. The function prototype as written is a bit misleading, because the second and subsequent calls ignore the $pageId parameter. In practice this isn't a problem because the page ID that's passed in is always the same, but still.

OK otherwise, marking OK.

Status & tagging log