r110412 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110411‎ | r110412 | r110413 >
Date:17:54, 31 January 2012
Author:gregchiasson
Status:ok (Comments)
Tags:aft 
Comment:
Remainder of the changes from r109565 - adds net_helpfulness as an actual column, rather than a calculated one, making sorting/fitlering on it less of a problem.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/alter.sql (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/sql/wmfupdate-jan31.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
@@ -15,7 +15,7 @@
1616 -- Stores feedback records: "user X submitted feedback on page Y, at time Z"
1717 CREATE TABLE IF NOT EXISTS /*_*/aft_article_feedback (
1818 -- Row ID (primary key)
19 - af_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 19+ af_id integer unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
2020 -- Foreign key to page.page_id
2121 af_page_id integer unsigned NOT NULL,
2222 -- User Id (0 if anon), and ip address
@@ -39,6 +39,8 @@
4040 af_abuse_count integer unsigned NOT NULL DEFAULT 0,
4141 af_helpful_count integer unsigned NOT NULL DEFAULT 0,
4242 af_unhelpful_count integer unsigned NOT NULL DEFAULT 0,
 43+ -- Net helpfulness (helpful - unhelpful). Used in fetch query.
 44+ af_net_helpfulness integer NOT NULL DEFAULT 0,
4345 -- Flag a message as requiring oversight, being hidden ,or being deleted
4446 af_needs_oversight boolean NOT NULL DEFAULT FALSE,
4547 af_is_deleted boolean NOT NULL DEFAULT FALSE,
Index: trunk/extensions/ArticleFeedbackv5/sql/wmfupdate-jan31.sql
@@ -11,6 +11,9 @@
1212 ADD COLUMN af_unhelpful_count integer unsigned NOT NULL DEFAULT 0,
1313 ADD COLUMN af_needs_oversight boolean NOT NULL DEFAULT FALSE,
1414 ADD COLUMN af_is_deleted boolean NOT NULL DEFAULT FALSE,
15 - ADD COLUMN af_is_hidden boolean NOT NULL DEFAULT FALSE;
 15+ ADD COLUMN af_is_hidden boolean NOT NULL DEFAULT FALSE,
 16+ ADD COLUMN af_net_helpfulness integer NOT NULL DEFAULT 0;
1617
17 -CREATE INDEX /*i*/afo_field_id ON /*_*/aft_article_field_option (afo_field_id);
\ No newline at end of file
 18+CREATE INDEX /*i*/afo_field_id ON /*_*/aft_article_field_option (afo_field_id);
 19+CREATE INDEX /*i*/af_net_helpfulness ON /*_*/aft_article_feedback (af_net_helpfulness);
 20+
Index: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
@@ -117,3 +117,8 @@
118118
119119 -- Added 1/31 (Roan)
120120 CREATE INDEX /*i*/afo_field_id ON /*_*/aft_article_field_option (afo_field_id);
 121+
 122+-- Added 1/31 (greg)
 123+ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_net_helpfulness integer NOT NULL DEFAULT 0;
 124+CREATE INDEX /*i*/af_net_helpfulness ON /*_*/aft_article_feedback (af_net_helpfulness);
 125+UPDATE aft_article_feedback SET af_net_helpfulness = CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED);
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -171,6 +171,16 @@
172172 $results['helpful'] = wfMessage( 'articlefeedbackv5-form-helpful-votes',
173173 $helpful, $unhelpful
174174 )->escaped();
 175+
 176+ // Update net_helpfulness after flagging as helpful/unhelpful.
 177+ $dbw->update(
 178+ 'aft_article_feedback',
 179+ array( 'af_net_helpfulness = CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED)' ),
 180+ array(
 181+ 'af_id' => $params['feedbackid'],
 182+ ),
 183+ __METHOD__
 184+ );
175185 }
176186
177187 // Conditional formatting for abuse flag
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -103,9 +103,7 @@
104104 // Build ORDER BY clause.
105105 switch( $sort ) {
106106 case 'helpful':
107 - $sortField = 'net_helpfulness';
108 - // Can't use aliases in mysql where clauses.
109 - $continueSql = "CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) $continueDirection";
 107+ $sortField = 'af_net_helpfulness';
110108 break;
111109 case 'rating':
112110 $sortField = 'rating';
@@ -114,10 +112,10 @@
115113 # Default field, fall through
116114 default:
117115 $sortField = 'af_id';
118 - $continueSql = "$sortField $continueDirection";
119116 break;
120117 }
121 - $order = "$sortField $direction";
 118+ $order = "$sortField $direction";
 119+ $continueSql = "$sortField $continueDirection";
122120
123121 // Build WHERE clause.
124122 // Filter applied , if any:
@@ -145,7 +143,7 @@
146144 ),
147145 array(
148146 'af_id',
149 - 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) AS net_helpfulness',
 147+ 'af_net_helpfulness',
150148 'rating.aa_response_boolean AS rating'
151149 ),
152150 $where,
@@ -189,8 +187,8 @@
190188 'af_helpful_count', 'af_unhelpful_count',
191189 'af_is_deleted', 'af_needs_oversight',
192190 '(SELECT COUNT(*) FROM ' . $dbr->tableName( 'revision' ) . ' WHERE rev_id > af_revision_id AND rev_page = ' . ( integer ) $pageId . ') AS age',
193 - 'CONVERT(af_helpful_count, SIGNED) - CONVERT(af_unhelpful_count, SIGNED) AS net_helpfulness',
194 - 'page_latest', 'af_revision_id', 'page_title', 'page_namespace',
 191+ 'af_net_helpfulness', 'af_revision_id',
 192+ 'page_latest', 'page_title', 'page_namespace',
195193 'rating.aa_response_boolean AS rating'
196194 ),
197195 array( 'af_id' => $ids ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r110520AFT5: Fix query-continue support for rating/helpfulness sorting. Refs r110412...gregchiasson21:16, 1 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109565AFT5 feedback page - allow sorting by helpfulness, and add unhelpful flag, pe...gregchiasson20:49, 19 January 2012

Comments

#Comment by Catrope (talk | contribs)   17:51, 1 February 2012

This looks good in terms of DB load, but I should point out that the continue feature won't work properly if you're sorting by anything other than ID. For instance, imagine you're sorting by helpfulness with limit=10, and there are more than 10 rows with net_helpfulness=3. Your code will either get in an infinite loop of showing the same results over and over again, or skip over a bunch of rows because it continues to the rows with net_helpfulness=4.

To make this work, you'd need to sort by, continue by, and index on, the (net_helpfulness, id) tuple. You can find examples in API modules in core MW, or talk to me for help.

#Comment by Gregchiasson (talk | contribs)   18:01, 1 February 2012

Yeah, I'd sort of realized that doing the continue like that might be a problem, for pretty much that exact reason. I'll see about fixing that.

Status & tagging log