Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | $rows = array(); |
100 | 100 | foreach ( $this->getDailyHighsAndLows() as $page ) { |
101 | 101 | $row = array(); |
102 | | - $pageTitle = Title::newFromText( $page['page'] ); |
| 102 | + $pageTitle = Title::newFromId( $page['page'] ); |
103 | 103 | $row['page'] = Linker::link( $pageTitle, $pageTitle->getPrefixedText() ); |
104 | 104 | foreach ( $page['ratings'] as $id => $value ) { |
105 | 105 | $row['rating-' . $id] = $value; |
— | — | @@ -197,31 +197,54 @@ |
198 | 198 | * This data should be updated daily, ideally though a scheduled batch job |
199 | 199 | */ |
200 | 200 | protected function getDailyHighsAndLows() { |
| 201 | + global $wgMemc; |
201 | 202 | |
202 | | - return array( |
203 | | - array( |
204 | | - 'page' => 'Main Page', |
205 | | - // List of ratings as the currently stand |
206 | | - 'ratings' => array( |
207 | | - 1 => 4, |
208 | | - 2 => 3, |
209 | | - 3 => 2, |
210 | | - 4 => 1, |
| 203 | + // check if we've got results in the cache |
| 204 | + $key = wfMemcKey( 'article_feedback_stats_highs_lows' ); |
| 205 | + $cache = $wgMemc->get( $key ); |
| 206 | + if ( $cache != false && $cache = -1 ) { |
| 207 | + $result = $cache; |
| 208 | + } else { |
| 209 | + $dbr = wfGetDB( DB_SLAVE ); |
| 210 | + // first find the freshest timestamp |
| 211 | + $row = $dbr->selectRow( |
| 212 | + 'article_feedback_stats_highs_lows', |
| 213 | + array( 'afshl_ts' ), |
| 214 | + "", |
| 215 | + __METHOD__, |
| 216 | + array( "ORDER BY" => "afshl_ts DESC", "LIMIT" => 1 ) |
| 217 | + ); |
| 218 | + |
| 219 | + // if we have no results, just return |
| 220 | + if ( !$row->afshl_ts ) { |
| 221 | + return; |
| 222 | + } |
| 223 | + |
| 224 | + // select ratings with that ts |
| 225 | + $result = $dbr->select( |
| 226 | + 'article_feedback_stats_highs_lows', |
| 227 | + array( |
| 228 | + 'afshl_page_id', |
| 229 | + 'afshl_avg_overall', |
| 230 | + 'afshl_avg_ratings' |
211 | 231 | ), |
212 | | - // Current average (considering historic averages of each rating) |
213 | | - 'average' => 2.5 |
214 | | - ), |
215 | | - array( |
216 | | - 'page' => 'Test Article', |
217 | | - 'ratings' => array( |
218 | | - 1 => 1, |
219 | | - 2 => 2, |
220 | | - 3 => 3, |
221 | | - 4 => 4, |
222 | | - ), |
223 | | - 'average' => 2.5 |
224 | | - ) |
225 | | - ); |
| 232 | + 'afshl_ts = ' . $row->afshl_ts, |
| 233 | + __METHOD__, |
| 234 | + array( "ORDER BY" => "afshl_avg_overall" ) |
| 235 | + ); |
| 236 | + $wgMemc->set( $key, $result, 86400 ); |
| 237 | + } |
| 238 | + |
| 239 | + $highs_lows = array(); |
| 240 | + foreach ( $result as $row ) { |
| 241 | + $highs_lows[] = array( |
| 242 | + 'page' => $row->afshl_page_id, |
| 243 | + 'ratings' => FormatJson::decode( $row->afshl_avg_ratings ), |
| 244 | + 'average' => $row->afshl_avg_overall |
| 245 | + ); |
| 246 | + } |
| 247 | + |
| 248 | + return $highs_lows; |
226 | 249 | } |
227 | 250 | |
228 | 251 | /** |
Index: trunk/extensions/ArticleFeedback/populateAFStatistics.php |
— | — | @@ -55,6 +55,7 @@ |
56 | 56 | } |
57 | 57 | |
58 | 58 | public function execute() { |
| 59 | + global $wgMemc; |
59 | 60 | $this->dbr = wfGetDB( DB_SLAVE ); |
60 | 61 | $this->dbw = wfGetDB( DB_MASTER ); |
61 | 62 | |
— | — | @@ -153,6 +154,31 @@ |
154 | 155 | $this->output( "Inserted " . $rowsInserted . " rows\n" ); |
155 | 156 | } |
156 | 157 | $this->output( "Done.\n" ); |
| 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 | + // loading data into caching |
| 167 | + $this->output( "Caching latest highs/lows.\n" ); |
| 168 | + $key = wfMemcKey( 'article_feedback_stats_highs_lows' ); |
| 169 | + $wgMemc->delete( $key ); |
| 170 | + $result = $this->dbr->select( |
| 171 | + 'article_feedback_stats_highs_lows', |
| 172 | + array( |
| 173 | + 'afshl_page_id', |
| 174 | + 'afshl_avg_overall', |
| 175 | + 'afshl_avg_ratings' |
| 176 | + ), |
| 177 | + 'afshl_ts = ' . $cur_ts, |
| 178 | + __METHOD__, |
| 179 | + array() |
| 180 | + ); |
| 181 | + $wgMemc->set( $key, $result, 86400 ); |
| 182 | + $this->output( "Done\n" ); |
157 | 183 | } |
158 | 184 | |
159 | 185 | |