r113980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113979‎ | r113980 | r113981 >
Date:00:16, 16 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on batch queries for special:studentactivity
Modified paths:
  • /trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
@@ -80,8 +80,8 @@
8181 protected $userNames = array();
8282
8383 /**
84 - * List of user ids with the names of their associated courses.
85 - * user id => array( course name 0, ... )
 84+ * List of course ids mapped to their title names.
 85+ * course id => course name
8686 *
8787 * @since 0.1
8888 * @var array
@@ -89,6 +89,24 @@
9090 protected $courseNames = array();
9191
9292 /**
 93+ * List of course ids pointing to the id of their org.
 94+ * course id => org id
 95+ *
 96+ * @since 0.1
 97+ * @var array
 98+ */
 99+ protected $courseOrgs = array();
 100+
 101+ /**
 102+ * List of org ids mapped to their title names.
 103+ * org id => org name
 104+ *
 105+ * @since 0.1
 106+ * @var array
 107+ */
 108+ protected $orgNames = array();
 109+
 110+ /**
93111 * Constructor.
94112 *
95113 * @param IContextSource $context
@@ -148,9 +166,36 @@
149167 wfWarn( 'User id not in $this->userNames in ' . __METHOD__ );
150168 }
151169 break;
152 - case 'first_enroll': case 'last_active':
153 - $value = htmlspecialchars( $this->getLanguage()->date( $value ) );
154 - break;
 170+ case 'last_active':
 171+ $value = htmlspecialchars( $this->getLanguage()->date( $value ) );
 172+ break;
 173+ case 'last_course':
 174+ if ( array_key_exists( $value, $this->courseNames ) ) {
 175+ $value = EPCourses::singleton()->getLinkFor( $this->courseNames[$value] );
 176+ }
 177+ else {
 178+ // TODO: enable
 179+ //wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ );
 180+ }
 181+ break;
 182+ case 'org_id':
 183+ $courseId = $this->currentObject->getField( 'last_course' );
 184+
 185+ if ( array_key_exists( $courseId, $this->courseOrgs ) ) {
 186+ $orgId = $this->courseOrgs[$courseId];
 187+
 188+ if ( array_key_exists( $orgId, $this->orgNames ) ) {
 189+ $value = EPOrgs::singleton()->getLinkFor( $this->orgNames[$orgId] );
 190+ }
 191+ else {
 192+ wfWarn( 'Org id not in $this->orgNames in ' . __METHOD__ );
 193+ }
 194+ }
 195+ else {
 196+ // TODO: enable
 197+ //wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ );
 198+ }
 199+ break;
155200 }
156201
157202 return $value;
@@ -201,10 +246,14 @@
202247 */
203248 protected function doBatchLookups() {
204249 $userIds = array();
205 - $field = $this->table->getPrefixedField( 'user_id' );
 250+ $courseIds = array();
206251
 252+ $userField = $this->table->getPrefixedField( 'user_id' );
 253+ $courseField = $this->table->getPrefixedField( 'last_course' );
 254+
207255 while( $student = $this->mResult->fetchObject() ) {
208 - $userIds[] = (int)$student->$field;
 256+ $userIds[] = (int)$student->$userField;
 257+ $courseIds[] = (int)$student->$courseField;
209258 }
210259
211260 if ( !empty( $userIds ) ) {
@@ -219,10 +268,26 @@
220269 $real = $user->user_real_name === '' ? $user->user_name : $user->user_real_name;
221270 $this->userNames[$user->user_id] = array( $user->user_name, $real );
222271 }
 272+ }
223273
224 - $courseNameField = EPCourses::singleton()->getPrefixedField( 'name' );
 274+ if ( !empty( $courseIds ) ) {
 275+ $courses = EPCourses::singleton()->selectFields(
 276+ array( 'id', 'name', 'org_id' ),
 277+ array( 'id' => array_unique( $courseIds ) )
 278+ );
225279
226 - // TODO: $this->courseNames[] =
 280+ $orgIds = array();
 281+
 282+ foreach ( $courses as $courseData ) {
 283+ $this->courseNames[$courseData['id']] = $courseData['name'];
 284+ $orgIds[] = $courseData['org_id'];
 285+ $this->courseOrgs[$courseData['id']] = $courseData['org_id'];
 286+ }
 287+
 288+ $this->orgNames = EPOrgs::singleton()->selectFields(
 289+ array( 'id', 'name' ),
 290+ array( 'id' => array_unique( $orgIds ) )
 291+ );
227292 }
228293 }
229294

Status & tagging log