r85575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85574‎ | r85575 | r85576 >
Date:21:21, 6 April 2011
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Added historic count, the total number of ratings, expired or not. Also added type casting to send known numetic values as real integers instead of strings.
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/api/ApiQueryArticleFeedback.php
@@ -34,21 +34,24 @@
3535 // Rating counts and totals
3636 $res = $this->select( __METHOD__ );
3737 $ratings = array( $params['pageid'] => array( 'pageid' => $params['pageid'] ) );
 38+ $historicCounts = $this->getHistoricCounts( $params );
3839 foreach ( $res as $i => $row ) {
3940 if ( !isset( $ratings[$params['pageid']]['revid'] ) ) {
40 - $ratings[$params['pageid']]['revid'] = $row->aap_revision;
 41+ $ratings[$params['pageid']]['revid'] = (int) $row->aap_revision;
4142 }
4243 if ( !isset( $ratings[$params['pageid']]['ratings'] ) ) {
4344 $ratings[$params['pageid']]['ratings'] = array();
4445 }
4546 $ratings[$params['pageid']]['ratings'][] = array(
46 - 'ratingid' => $row->aap_rating_id,
 47+ 'ratingid' => (int) $row->aap_rating_id,
4748 'ratingdesc' => $row->aar_rating,
48 - 'total' => $row->aap_total,
49 - 'count' => $row->aap_count,
 49+ 'total' => (int) $row->aap_total,
 50+ 'count' => (int) $row->aap_count,
 51+ 'countall' => isset( $historicCounts[$row->aap_rating_id] )
 52+ ? $historicCounts[$row->aap_rating_id] + 100 : 0
5053 );
5154 }
52 -
 55+
5356 // User-specific data
5457 $ratings[$params['pageid']]['status'] = 'current';
5558 if ( $params['userrating'] ) {
@@ -102,10 +105,33 @@
103106 $result->setIndexedTagName( $rat['ratings'], 'r' );
104107 $result->addValue( array( 'query', $this->getModuleName() ), null, $rat );
105108 }
106 -
 109+
107110 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'aa' );
108111 }
109 -
 112+
 113+ protected function getHistoricCounts( $params ) {
 114+ global $wgArticleFeedbackRatings;
 115+
 116+ $res = $this->getDB()->select(
 117+ 'article_feedback_pages',
 118+ array(
 119+ 'aap_rating_id',
 120+ 'SUM(aap_count) as count',
 121+ ),
 122+ array(
 123+ 'aap_page_id' => $params['pageid'],
 124+ 'aap_rating_id' => $wgArticleFeedbackRatings,
 125+ ),
 126+ __METHOD__,
 127+ array( 'GROUP BY' => 'aap_rating_id')
 128+ );
 129+ $counts = array();
 130+ foreach ( $res as $row ) {
 131+ $counts[$row->aap_rating_id] = $row->count;
 132+ }
 133+ return $counts;
 134+ }
 135+
110136 protected function getAnonToken( $params ) {
111137 global $wgUser;
112138

Follow-up revisions

RevisionCommit summaryAuthorDate
r85576Removed some code that was left over from experimenting with the countall par...tparscal21:23, 6 April 2011

Comments

#Comment by Catrope (talk | contribs)   20:26, 12 April 2011

Trevor and I discussed this, putting it in here for future reference:

+	protected function getHistoricCounts( $params ) {
+		global $wgArticleFeedbackRatings;
+		
+		$res = $this->getDB()->select(
+			'article_feedback_pages',
+			array(
+				'aap_rating_id',
+				'SUM(aap_count) as count',
+			),
+			array(
+				'aap_page_id' => $params['pageid'],
+				'aap_rating_id' => $wgArticleFeedbackRatings,
+			),
+			__METHOD__,
+			array( 'GROUP BY' => 'aap_rating_id')
+		);
+		$counts = array();
+		foreach ( $res as $row ) {
+			$counts[$row->aap_rating_id] = $row->count;
+		}
+		return $counts;
+	}

This needs to go in a summary table for efficient querying. Now that we have a use case for per-page summary data, we might as well restore article_feedback_pages to its original role of tracking per-page data, and move the per-revision tracking to a separate table.

Status & tagging log