r87522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87521‎ | r87522 | r87523 >
Date:00:14, 6 May 2011
Author:awjrichards
Status:resolved
Tags:
Comment:
Followup r87402, r87381, r87379

* Functionalized creation of array data store for highs/lows from database object for easy reuse
* Now caching data object of highs/lows rather than full DB result object
* Now relying on data store array generation in special page to generate data for cache population in maint script
* Wrapped 'where' clauses for database abstraction layer in arrays
* Switched to use += array_slice() when munging highest and lowest of the highs/lows rather than array_merge to prevent overwriting keys
* Switched to using isset() rather in_array( blah, array_keys()) for simplicity's sake
* No longer checking for availability of cache before attempting to populate it in maintenance script
Modified paths:
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/populateAFStatistics.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -221,8 +221,8 @@
222222 // check if we've got results in the cache
223223 $key = wfMemcKey( 'article_feedback_stats_highs_lows' );
224224 $cache = $wgMemc->get( $key );
225 - if ( $cache instanceof ResultsWrapper ) {
226 - $result = $cache;
 225+ if ( is_array( $cache )) {
 226+ $highs_lows = $cache;
227227 } else {
228228 $dbr = wfGetDB( DB_SLAVE );
229229 // first find the freshest timestamp
@@ -247,13 +247,23 @@
248248 'afshl_avg_overall',
249249 'afshl_avg_ratings'
250250 ),
251 - 'afshl_ts = ' . $row->afshl_ts,
 251+ array( 'afshl_ts = ' . $row->afshl_ts),
252252 __METHOD__,
253253 array( "ORDER BY" => "afshl_avg_overall" )
254254 );
255 - $wgMemc->set( $key, $result, 86400 );
 255+ $highs_lows = $this->buildHighsAndLows( $result );
 256+ $wgMemc->set( $key, $highs_lows, 86400 );
256257 }
257258
 259+ return $highs_lows;
 260+ }
 261+
 262+ /**
 263+ * Build data store of highs/lows for use when rendering table
 264+ * @param object Database result
 265+ * @return array
 266+ */
 267+ public function buildHighsAndLows( $result ) {
258268 $highs_lows = array();
259269 foreach ( $result as $row ) {
260270 $highs_lows[] = array(
@@ -262,10 +272,9 @@
263273 'average' => $row->afshl_avg_overall
264274 );
265275 }
266 -
267276 return $highs_lows;
268277 }
269 -
 278+
270279 /**
271280 * Gets a list of articles which have quickly changing ratings.
272281 *
Index: trunk/extensions/ArticleFeedback/populateAFStatistics.php
@@ -71,7 +71,7 @@
7272 'aa_rating_value',
7373 'aa_rating_id'
7474 ),
75 - 'aa_timestamp >= ' . $this->getLowerBoundTimestamp(),
 75+ array( 'aa_timestamp >= ' . $this->getLowerBoundTimestamp() ),
7676 __METHOD__,
7777 array() // better to do with limits and offsets?
7878 );
@@ -117,7 +117,7 @@
118118 // take lowest 50 and highest 50
119119 $highest_and_lowest_page_ids = array_slice( $averages, 0, 50, true );
120120 if ( count( $averages ) > 50 ) {
121 - $highest_and_lowest_page_ids = array_merge( $highest_and_lowest_page_ids, array_slice( $averages, -50, 50, true ));
 121+ $highest_and_lowest_page_ids += array_slice( $averages, -50, 50, true );
122122 }
123123 $this->output( "Done\n" );
124124
@@ -127,7 +127,7 @@
128128 $rows = array();
129129 foreach( $highs_and_lows as $page_id => $data ) {
130130 // make sure this is one of the highest/lowest average ratings
131 - if ( !in_array( $page_id, array_keys( $highest_and_lowest_page_ids ))) {
 131+ if ( !isset( $highest_and_lowest_page_ids[ $page_id ] )) {
132132 continue;
133133 }
134134 $rows[] = array(
@@ -155,17 +155,9 @@
156156 }
157157 $this->output( "Done.\n" );
158158
159 - // check to see whether we should bother caching
160 - if ( is_a( $wgMemc, 'EmptyBagOStuff' )) {
161 - $this->output( "Object caching not available.\n" );
162 - $this->output( "Done.\n" );
163 - return;
164 - }
165 -
166159 // loading data into caching
167 - $this->output( "Caching latest highs/lows.\n" );
 160+ $this->output( "Caching latest highs/lows (if cache present).\n" );
168161 $key = wfMemcKey( 'article_feedback_stats_highs_lows' );
169 - $wgMemc->delete( $key );
170162 $result = $this->dbr->select(
171163 'article_feedback_stats_highs_lows',
172164 array(
@@ -177,7 +169,11 @@
178170 __METHOD__,
179171 array()
180172 );
181 - $wgMemc->set( $key, $result, 86400 );
 173+ // grab the article feedback special page so we can reuse the data structure building code
 174+ $sp = SpecialPageFactory::getPage( 'ArticleFeedback' );
 175+ $highs_lows = $sp->buildHighsAndLows( $result );
 176+ // stash the data structure in the cache
 177+ $wgMemc->set( $key, $highs_lows, 86400 );
182178 $this->output( "Done\n" );
183179 }
184180

Follow-up revisions

RevisionCommit summaryAuthorDate
r87718ArticleFeedback: Fix escaping in r87310, r87522catrope14:48, 9 May 2011
r87719ArticleFeedback: Fix for r87522: SpecialPageFactory doesn't exist in 1.17wmf1...catrope14:52, 9 May 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87379Follow up r87310; Adding index to timestamp files in article_feedback and art...awjrichards01:25, 4 May 2011
r87381Now actually determing only the top and bottom 50 rated pagesawjrichards01:51, 4 May 2011
r87402Added caching of latest highs/lows in high/low populating maintenance script;...awjrichards15:08, 4 May 2011

Status & tagging log