r82885 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82884‎ | r82885 | r82886 >
Date:09:16, 27 February 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Refactored loadStableRevAndConfig() to reduce queries with FR_MASTER
* Renamed pendingRevs field to pendingRevCount
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -7,10 +7,13 @@
88 class FlaggedArticle extends Article {
99 /* Process cache variables */
1010 protected $stableRev = null;
11 - protected $pendingRevs = null;
 11+ protected $revsArePending = null;
 12+ protected $pendingRevCount = null;
1213 protected $pageConfig = null;
1314 protected $imagePage = null; // for file pages
1415
 16+ protected $stabilityDataLoaded = false;
 17+
1518 /**
1619 * Get a FlaggedArticle for a given title
1720 * @param Title
@@ -39,9 +42,12 @@
4043 */
4144 public function clear() {
4245 $this->stableRev = null;
43 - $this->pendingRevs = null;
 46+ $this->revsArePending = null;
 47+ $this->pendingRevCount = null;
4448 $this->pageConfig = null;
4549 $this->imagePage = null;
 50+
 51+ $this->stabilityDataLoaded = false;
4652 parent::clear();
4753 }
4854
@@ -81,10 +87,11 @@
8288 * @return bool
8389 */
8490 public function isStableShownByDefault( $flags = 0 ) {
85 - if ( !$this->isReviewable( $flags ) ) {
 91+ $this->loadFlaggedRevsData( $flags );
 92+ if ( !$this->isReviewable() ) {
8693 return false; // no stable versions can exist
8794 }
88 - $config = $this->getStabilitySettings( $flags ); // page configuration
 95+ $config = $this->getStabilitySettings(); // page configuration
8996 return (bool)$config['override'];
9097 }
9198
@@ -94,10 +101,11 @@
95102 * @return bool
96103 */
97104 public function editsRequireReview( $flags = 0 ) {
 105+ $this->loadFlaggedRevsData( $flags );
98106 return (
99 - $this->isReviewable( $flags ) && // reviewable page
100 - $this->isStableShownByDefault( $flags ) && // and stable versions override
101 - $this->getStableRev( $flags ) // and there is a stable version
 107+ $this->isReviewable() && // reviewable page
 108+ $this->isStableShownByDefault() && // and stable versions override
 109+ $this->getStableRev() // and there is a stable version
102110 );
103111 }
104112
@@ -107,18 +115,8 @@
108116 * @return bool
109117 */
110118 public function revsArePending( $flags = 0 ) {
111 - if ( $this->isReviewable() ) {
112 - $srev = $this->getStableRev( $flags );
113 - if ( $srev ) {
114 - if ( $flags & FR_MASTER ) {
115 - $latest = $this->getTitle()->getLatestRevID( Title::GAID_FOR_UPDATE );
116 - } else {
117 - $latest = $this->getLatest();
118 - }
119 - return ( $srev->getRevId() != $latest ); // edits need review
120 - }
121 - }
122 - return false; // all edits go live
 119+ $this->loadFlaggedRevsData( $flags );
 120+ return $this->revsArePending;
123121 }
124122
125123 /**
@@ -129,11 +127,11 @@
130128 */
131129 public function getPendingRevCount( $flags = 0 ) {
132130 global $wgMemc, $wgParserCacheExpireTime;
133 - # Cached results available?
134 - if ( !( $flags & FR_MASTER ) && $this->pendingRevs !== null ) {
135 - return $this->pendingRevs;
 131+ $this->loadFlaggedRevsData( $flags );
 132+ if ( !( $flags & FR_MASTER ) && $this->pendingRevCount !== null ) {
 133+ return $this->pendingRevCount; // use process cache
136134 }
137 - $srev = $this->getStableRev( $flags );
 135+ $srev = $this->getStableRev();
138136 if ( !$srev ) {
139137 return 0; // none
140138 }
@@ -166,8 +164,8 @@
167165 $data = FlaggedRevs::makeMemcObj( "{$sRevId}-{$count}" );
168166 $wgMemc->set( $key, $data, $wgParserCacheExpireTime );
169167 }
170 - $this->pendingRevs = $count;
171 - return $this->pendingRevs;
 168+ $this->pendingRevCount = $count;
 169+ return $this->pendingRevCount;
172170 }
173171
174172 /**
@@ -255,12 +253,13 @@
256254 * @return bool
257255 */
258256 public function isReviewable( $flags = 0 ) {
 257+ $this->loadFlaggedRevsData( $flags );
259258 if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) {
260259 return false;
261260 }
262261 # Check if flagging is disabled for this page via config
263262 if ( FlaggedRevs::useOnlyIfProtected() ) {
264 - $config = $this->getStabilitySettings( $flags ); // page configuration
 263+ $config = $this->getStabilitySettings(); // page configuration
265264 return (bool)$config['override']; // stable is default or flagging disabled
266265 }
267266 return true;
@@ -294,14 +293,8 @@
295294 * @return mixed (FlaggedRevision/null)
296295 */
297296 public function getStableRev( $flags = 0 ) {
298 - # Cached results available?
299 - if ( $this->stableRev === null || ( $flags & FR_MASTER ) ) {
300 - $this->loadStableRevAndConfig( $flags );
301 - }
302 - if ( $this->stableRev ) {
303 - return $this->stableRev;
304 - }
305 - return null; // false => null
 297+ $this->loadFlaggedRevsData( $flags );
 298+ return $this->stableRev ? $this->stableRev : null; // false => null
306299 }
307300
308301 /**
@@ -310,10 +303,7 @@
311304 * @return array (select,override)
312305 */
313306 public function getStabilitySettings( $flags = 0 ) {
314 - if ( !( $flags & FR_MASTER ) && $this->pageConfig !== null ) {
315 - return $this->pageConfig; // use process cache
316 - }
317 - $this->loadStableRevAndConfig( $flags);
 307+ $this->loadFlaggedRevsData( $flags );
318308 return $this->pageConfig;
319309 }
320310
@@ -322,9 +312,17 @@
323313 * @param Title $title, page title
324314 * @param int $flags FR_MASTER
325315 */
326 - protected function loadStableRevAndConfig( $flags = 0 ) {
 316+ protected function loadFlaggedRevsData( $flags = 0 ) {
 317+ if ( $this->stabilityDataLoaded && !( $flags & FR_MASTER ) ) {
 318+ return; // no need to reload everything
 319+ }
 320+ $this->stabilityDataLoaded = true;
 321+
 322+ $this->pageConfig = FlaggedPageConfig::getDefaultVisibilitySettings(); // default
327323 $this->stableRev = false; // false => "found nothing"
328 - $this->pageConfig = FlaggedPageConfig::getDefaultVisibilitySettings(); // default
 324+ $this->revsArePending = false;
 325+ $this->pendingRevCount = null; // defer this one
 326+
329327 if ( !FlaggedRevs::inReviewNamespace( $this->getTitle() ) ) {
330328 return; // short-circuit
331329 }
@@ -333,7 +331,8 @@
334332 wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
335333 $row = $db->selectRow(
336334 array( 'page', 'flaggedpages', 'flaggedrevs', 'flaggedpage_config' ),
337 - array_merge( FlaggedRevision::selectFields(), FlaggedPageConfig::selectFields() ),
 335+ array_merge( FlaggedRevision::selectFields(),
 336+ FlaggedPageConfig::selectFields(), array( 'fp_pending_since' ) ),
338337 array( 'page_id' => $this->getID() ),
339338 __METHOD__,
340339 array(),
@@ -355,5 +354,6 @@
356355 $this->stableRev = new FlaggedRevision( $row );
357356 }
358357 }
 358+ $this->revsArePending = ( $row->fp_pending_since !== null ); // revs await review
359359 }
360360 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r85689Simple performance tweak to isReviewable() (fixes regression)aaron20:47, 8 April 2011

Status & tagging log