Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php |
— | — | @@ -221,8 +221,8 @@ |
222 | 222 | // check if we've got results in the cache |
223 | 223 | $key = wfMemcKey( 'article_feedback_stats_highs_lows' ); |
224 | 224 | $cache = $wgMemc->get( $key ); |
225 | | - if ( $cache instanceof ResultsWrapper ) { |
226 | | - $result = $cache; |
| 225 | + if ( is_array( $cache )) { |
| 226 | + $highs_lows = $cache; |
227 | 227 | } else { |
228 | 228 | $dbr = wfGetDB( DB_SLAVE ); |
229 | 229 | // first find the freshest timestamp |
— | — | @@ -247,13 +247,23 @@ |
248 | 248 | 'afshl_avg_overall', |
249 | 249 | 'afshl_avg_ratings' |
250 | 250 | ), |
251 | | - 'afshl_ts = ' . $row->afshl_ts, |
| 251 | + array( 'afshl_ts = ' . $row->afshl_ts), |
252 | 252 | __METHOD__, |
253 | 253 | array( "ORDER BY" => "afshl_avg_overall" ) |
254 | 254 | ); |
255 | | - $wgMemc->set( $key, $result, 86400 ); |
| 255 | + $highs_lows = $this->buildHighsAndLows( $result ); |
| 256 | + $wgMemc->set( $key, $highs_lows, 86400 ); |
256 | 257 | } |
257 | 258 | |
| 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 ) { |
258 | 268 | $highs_lows = array(); |
259 | 269 | foreach ( $result as $row ) { |
260 | 270 | $highs_lows[] = array( |
— | — | @@ -262,10 +272,9 @@ |
263 | 273 | 'average' => $row->afshl_avg_overall |
264 | 274 | ); |
265 | 275 | } |
266 | | - |
267 | 276 | return $highs_lows; |
268 | 277 | } |
269 | | - |
| 278 | + |
270 | 279 | /** |
271 | 280 | * Gets a list of articles which have quickly changing ratings. |
272 | 281 | * |
Index: trunk/extensions/ArticleFeedback/populateAFStatistics.php |
— | — | @@ -71,7 +71,7 @@ |
72 | 72 | 'aa_rating_value', |
73 | 73 | 'aa_rating_id' |
74 | 74 | ), |
75 | | - 'aa_timestamp >= ' . $this->getLowerBoundTimestamp(), |
| 75 | + array( 'aa_timestamp >= ' . $this->getLowerBoundTimestamp() ), |
76 | 76 | __METHOD__, |
77 | 77 | array() // better to do with limits and offsets? |
78 | 78 | ); |
— | — | @@ -117,7 +117,7 @@ |
118 | 118 | // take lowest 50 and highest 50 |
119 | 119 | $highest_and_lowest_page_ids = array_slice( $averages, 0, 50, true ); |
120 | 120 | 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 ); |
122 | 122 | } |
123 | 123 | $this->output( "Done\n" ); |
124 | 124 | |
— | — | @@ -127,7 +127,7 @@ |
128 | 128 | $rows = array(); |
129 | 129 | foreach( $highs_and_lows as $page_id => $data ) { |
130 | 130 | // 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 ] )) { |
132 | 132 | continue; |
133 | 133 | } |
134 | 134 | $rows[] = array( |
— | — | @@ -155,17 +155,9 @@ |
156 | 156 | } |
157 | 157 | $this->output( "Done.\n" ); |
158 | 158 | |
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 | | - |
166 | 159 | // loading data into caching |
167 | | - $this->output( "Caching latest highs/lows.\n" ); |
| 160 | + $this->output( "Caching latest highs/lows (if cache present).\n" ); |
168 | 161 | $key = wfMemcKey( 'article_feedback_stats_highs_lows' ); |
169 | | - $wgMemc->delete( $key ); |
170 | 162 | $result = $this->dbr->select( |
171 | 163 | 'article_feedback_stats_highs_lows', |
172 | 164 | array( |
— | — | @@ -177,7 +169,11 @@ |
178 | 170 | __METHOD__, |
179 | 171 | array() |
180 | 172 | ); |
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 ); |
182 | 178 | $this->output( "Done\n" ); |
183 | 179 | } |
184 | 180 | |