r114027 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114026‎ | r114027 | r114028 >
Date:18:33, 16 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on caching special:studentactivity and fixed image display
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.settings.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.settings.php
@@ -40,7 +40,7 @@
4141 'ambassadorCommonsUrl' => 'https://commons.wikimedia.org/wiki/Special:UploadWizard',
4242 'citylessCountries' => array( 'BT', 'BV', 'IO', 'VG', 'TD', 'CX', 'CC', 'KM', 'DJ', 'GQ', 'FK', 'FX', 'TF', 'GW', 'HM', 'KI', 'YT', 'MS', 'NR', 'NU', 'NF', 'PN', 'SH', 'PM', 'WS', 'SC', 'GS', 'SJ', 'TK', 'TP', 'TV', 'UM', 'VU', 'EH' ),
4343 'ambassadorImgWidth' => 140,
44 - 'recentActivityLimit' => 17 * 60 * 60,
 44+ 'recentActivityLimit' => 24 * 60 * 60,
4545 'resourceDir' => $resourceDir,
4646 'imageDir' => $resourceDir . 'images/',
4747 );
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
@@ -32,14 +32,35 @@
3333 public function execute( $subPage ) {
3434 parent::execute( $subPage );
3535
 36+ $cache = wfGetCache( CACHE_ANYTHING );
 37+ $cacheKey = wfMemcKey( get_class( $this ), $this->getLanguage()->getCode() );
 38+ $cachedHTML = $cache->get( $cacheKey );
 39+
 40+ $out = $this->getOutput();
 41+
 42+ if ( $this->getRequest()->getText( 'action' ) !== 'purge' && is_string( $cachedHTML ) ) {
 43+ $html = $cachedHTML;
 44+ }
 45+ else {
 46+ $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes(
 47+ wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) )
 48+ ) );
 49+
 50+ $this->displayStudentMeter( $conds );
 51+ $this->displayPager( $conds );
 52+
 53+ $html = $out->getHTML();
 54+ $cache->set( $cacheKey, $html, 3600 );
 55+ }
 56+
 57+ $out->clearHTML();
 58+
3659 $this->displayNavigation();
3760
38 - $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes(
39 - wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) )
40 - ) );
 61+ $out->addHTML( $html );
 62+ }
4163
42 - $this->showStudentMeter( $conds );
43 -
 64+ public function displayPager( array $conds ) {
4465 $out = $this->getOutput();
4566
4667 $pager = new EPStudentActivityPager( $this->getContext(), $conds );
@@ -59,14 +80,14 @@
6081 }
6182 }
6283
63 - public function showStudentMeter( array $conds ) {
 84+ public function displayStudentMeter( array $conds ) {
6485 $studentCount = EPStudents::singleton()->count( $conds );
6586
6687 if ( $studentCount < 10 ) {
6788 $image = $studentCount < 5 ? 0 : 5;
6889 }
6990 else {
70 - $image = floor( $studentCount / 10 );
 91+ $image = min( round( $studentCount / 10 ) * 10, 60 );
7192 }
7293
7394 $message = $this->msg( 'ep-studentactivity-count', $studentCount )->escaped();
Index: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
@@ -113,7 +113,8 @@
114114 $value = EPCourses::singleton()->getLinkFor( $this->courseNames[$value] );
115115 }
116116 else {
117 - wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ );
 117+ // TODO: enable
 118+ //wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ );
118119 }
119120 break;
120121 case 'org_id':
@@ -130,7 +131,8 @@
131132 }
132133 }
133134 else {
134 - wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ );
 135+ // TODO: enable
 136+ //wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ );
135137 }
136138 break;
137139 }

Status & tagging log