r114181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114180‎ | r114181 | r114182 >
Date:20:51, 19 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on caching of special:student
Modified paths:
  • /trunk/extensions/EducationProgram/specials/SpecialEPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -35,7 +35,7 @@
3636 parent::execute( $subPage );
3737
3838 if ( $this->subPage === '' ) {
39 - $this->startCache( 3600, $this->getUser()->isAnon() );
 39+ $this->startCache( 3600 );
4040
4141 $this->displayNavigation();
4242
@@ -60,9 +60,7 @@
6161 protected function getCacheKey() {
6262 $values = $this->getRequest()->getValues();
6363
64 - if ( array_key_exists( 'action', $values ) && $values['action'] === 'purge' ) {
65 - unset( $values['action'] );
66 - }
 64+ $values[] = $this->getUser()->getId();
6765
6866 return array_merge( $values, parent::getCacheKey() );
6967 }
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -150,39 +150,56 @@
151151 * @param array $summaryData
152152 */
153153 protected function displaySummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) {
154 - $out = $this->getOutput();
 154+ $this->getOutput()->addHTML( $item, $collapsed, $summaryData );
 155+ }
155156
 157+ /**
 158+ * Display the summary data.
 159+ *
 160+ * @since 0.1
 161+ *
 162+ * @param DBDataObject $item
 163+ * @param boolean $collapsed
 164+ * @param array $summaryData
 165+ *
 166+ * @return string
 167+ */
 168+ protected function getSummary( DBDataObject $item, $collapsed = false, array $summaryData = null ) {
 169+ $html = '';
 170+
156171 $class = 'wikitable ep-summary mw-collapsible';
157172
158173 if ( $collapsed ) {
159174 $class .= ' mw-collapsed';
160175 }
161176
162 - $out->addHTML( Html::openElement( 'table', array( 'class' => $class ) ) );
 177+ $html .= Html::openElement( 'table', array( 'class' => $class ) );
163178
164 - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>' );
 179+ $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-item-summary' ) ) . '</tr>';
165180
166181 $summaryData = is_null( $summaryData ) ? $this->getSummaryData( $item ) : $summaryData;
167182
168183 foreach ( $summaryData as $stat => $value ) {
169 - $out->addHTML( '<tr>' );
 184+ $html .= '<tr>';
170185
171 - $out->addElement(
 186+ $html .= Html::element(
172187 'th',
173188 array( 'class' => 'ep-summary-name' ),
174189 wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat )
175190 );
176191
177 - $out->addHTML( Html::rawElement(
 192+ $html .= Html::rawElement(
178193 'td',
179194 array( 'class' => 'ep-summary-value' ),
180195 $value
181 - ) );
 196+ );
182197
183 - $out->addHTML( '</tr>' );
 198+ $html .= '</tr>';
184199 }
185200
186 - $out->addHTML( Html::closeElement( 'table' ) );
 201+ $html .= Html::closeElement( 'table' );
 202+
 203+ return $html;
187204 }
188205
189206 /**
Index: trunk/extensions/EducationProgram/specials/SpecialStudent.php
@@ -38,13 +38,20 @@
3939 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Students' )->getLocalURL() );
4040 }
4141 else {
 42+ $this->startCache( 3600 );
 43+
4244 $this->displayNavigation();
4345
4446 $student = false;
4547 $user = User::newFromName( $subPage );
4648
4749 if ( $user !== false && $user->getId() !== 0 ) {
48 - $student = EPStudents::singleton()->selectRow( null, array( 'user_id' => $user->getId() ) );
 50+ $student = $this->getCachedValue(
 51+ function( $userId ) {
 52+ return EPStudents::singleton()->selectRow( null, array( 'user_id' => $userId ) );
 53+ },
 54+ $user->getId()
 55+ );
4956 }
5057
5158 if ( $student === false ) {
@@ -53,27 +60,49 @@
5461 else {
5562 $out->setPageTitle( wfMsgExt( 'ep-student-title', 'parsemag', $student->getName() ) );
5663
57 - $this->displaySummary( $student );
 64+ $this->addCachedHTML( array( $this, 'getSummary' ), $student );
5865
59 - $courseIds = array_map(
60 - function( EPCourse $course ) {
61 - return $course->getId();
62 - },
63 - $student->getCourses( 'id' )
64 - );
 66+ $this->addCachedHTML( function( EPStudent $student ) {
 67+ $courseIds = array_map(
 68+ function( EPCourse $course ) {
 69+ return $course->getId();
 70+ },
 71+ $student->getCourses( 'id' )
 72+ );
6573
66 - if ( empty( $courseIds ) ) {
67 - // TODO: high
68 - }
69 - else {
70 - $out->addElement( 'h2', array(), wfMsg( 'ep-student-courses' ) );
71 - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) );
72 - }
 74+ $html = '';
 75+
 76+ if ( empty( $courseIds ) ) {
 77+ // TODO: high
 78+ }
 79+ else {
 80+ $html .= Html::element( 'h2', array(), wfMsg( 'ep-student-courses' ) );
 81+ $html .= ''; // TODO
 82+ // EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) );
 83+ }
 84+
 85+ return $html;
 86+ }, $student );
7387 }
 88+
 89+ $this->saveCache();
7490 }
7591 }
7692
7793 /**
 94+ * @see SpecialCachedPage::getCacheKey
 95+ * @return array
 96+ */
 97+ protected function getCacheKey() {
 98+ $values = $this->getRequest()->getValues();
 99+
 100+ $values[] = $this->getUser()->getId();
 101+ $values[] = $this->subPage;
 102+
 103+ return array_merge( $values, parent::getCacheKey() );
 104+ }
 105+
 106+ /**
78107 * Gets the summary data.
79108 *
80109 * @since 0.1

Status & tagging log