r113609 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113608‎ | r113609 | r113610 >
Date:03:32, 12 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
optimize courses pager
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPArticleTable.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php
@@ -518,9 +518,9 @@
519519 */
520520 protected function doBatchLookups() {
521521 $userIds = array();
 522+ $field = $this->table->getPrefixedField( 'org_id' );
522523
523524 while( $student = $this->mResult->fetchObject() ) {
524 - $field = EPStudents::singleton()->getPrefixedField( 'user_id' );
525525 $userIds[] = $student->$field;
526526 $this->articles[$student->$field] = array();
527527 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -20,6 +20,15 @@
2121 * @var boolean
2222 */
2323 protected $readOnlyMode;
 24+
 25+ /**
 26+ * List of org names, looked up in batch before the rows are displayed.
 27+ * org id => org name
 28+ *
 29+ * @since 0.1
 30+ * @var array
 31+ */
 32+ protected $orgNames;
2433
2534 /**
2635 * Constructor.
@@ -72,15 +81,11 @@
7382 public function getFormattedValue( $name, $value ) {
7483 switch ( $name ) {
7584 case 'name':
76 - $value = EPCourses::singleton()->getLinkFor( $value );
 85+ $value = $this->table->getLinkFor( $value );
7786 break;
7887 case 'org_id':
79 - $org = EPOrgs::singleton()->selectRow( 'name', array( 'id' => $value ) );
80 -
81 - // This should not happen. A course should always have an org.
82 - // But if something gets messed up somehow, just display the ID rather then throwing a fatal.
83 - if ( $org !== false ) {
84 - $value = $org->getLink();
 88+ if ( array_key_exists( $value, $this->orgNames ) ) {
 89+ $value = EPOrgs::singleton()->getLinkFor( $this->orgNames[$value] );
8590 }
8691 break;
8792 case 'term':
@@ -268,4 +273,22 @@
269274 return !$this->readOnlyMode;
270275 }
271276
 277+ /**
 278+ * (non-PHPdoc)
 279+ * @see IndexPager::doBatchLookups()
 280+ */
 281+ protected function doBatchLookups() {
 282+ $orgIds = array();
 283+ $field = $this->table->getPrefixedField( 'org_id' );
 284+
 285+ while( $course = $this->mResult->fetchObject() ) {
 286+ $orgIds[] = $course->$field;
 287+ }
 288+
 289+ $this->orgNames = EPOrgs::singleton()->selectFields(
 290+ array( 'id', 'name' ),
 291+ array( 'id' => $orgIds )
 292+ );
 293+ }
 294+
272295 }

Status & tagging log