r87616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87615‎ | r87616 | r87617 >
Date:00:45, 7 May 2011
Author:aaron
Status:ok
Tags:
Comment:
* Follow-up r86179: code changes to make use of index changes. Uses timestamp as time order rather than rev_id.
* Optimized determineStable() a bit with useOnlyIfProtected() check
* Removed some code duplication in determineStable() and removed '1=1' condition.
Modified paths:
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedPage.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedPage.php
@@ -342,14 +342,14 @@
343343 'fr_rev_id',
344344 array(
345345 'fr_page_id' => $this->getId(),
346 - 'rev_page = fr_page_id',
 346+ 'rev_page = fr_page_id', // sanity
347347 'rev_id = fr_rev_id',
348348 'rev_deleted & ' . Revision::DELETED_TEXT => 0
349349 ),
350350 __METHOD__,
351351 array(
352 - 'ORDER BY' => 'fr_quality DESC, fr_rev_id DESC',
353 - 'USE INDEX' => array( 'flaggedrevs' => 'page_qal_rev', 'revision' => 'PRIMARY' )
 352+ 'ORDER BY' => 'fr_quality DESC, fr_rev_timestamp DESC',
 353+ 'USE INDEX' => array( 'flaggedrevs' => 'page_qal_time' )
354354 )
355355 );
356356 return (int)$oldid;
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php
@@ -191,67 +191,67 @@
192192 if ( !$pageId ) {
193193 return null; // short-circuit query
194194 }
195 - # Get visiblity settings...
196 - if ( empty( $config ) ) {
197 - $config = FlaggedPageConfig::getStabilitySettings( $title, $flags );
 195+ # Get visiblity settings to see if page is reviewable...
 196+ if ( FlaggedRevs::useOnlyIfProtected() ) {
 197+ if ( empty( $config ) ) {
 198+ $config = FlaggedPageConfig::getStabilitySettings( $title, $flags );
 199+ }
 200+ if ( !$config['override'] ) {
 201+ return null; // page is not reviewable; no stable version
 202+ }
198203 }
199 - if ( !$config['override'] && FlaggedRevs::useOnlyIfProtected() ) {
200 - return null; // page is not reviewable; no stable version
201 - }
 204+ $baseConds = array(
 205+ 'fr_page_id' => $pageId,
 206+ 'rev_id = fr_rev_id',
 207+ 'rev_page = fr_page_id', // sanity
 208+ 'rev_deleted & ' . Revision::DELETED_TEXT => 0
 209+ );
 210+ $options['ORDER BY'] = 'fr_rev_timestamp DESC';
 211+
202212 $row = null;
203 - $options['ORDER BY'] = 'fr_rev_id DESC';
204 - # Look for the latest pristine revision...
205 - if ( FlaggedRevs::pristineVersions() && $precedence !== 'latest' ) {
206 - $prow = $db->selectRow(
207 - array( 'flaggedrevs', 'revision' ),
208 - self::selectFields(),
209 - array( 'fr_page_id' => $pageId,
210 - 'fr_quality = ' . FR_PRISTINE,
211 - 'rev_id = fr_rev_id',
212 - 'rev_page = fr_page_id',
213 - 'rev_deleted & ' . Revision::DELETED_TEXT => 0
214 - ),
215 - __METHOD__,
216 - $options
217 - );
218 - # Looks like a plausible revision
219 - $row = $prow ? $prow : $row;
 213+ if ( $precedence !== 'latest' ) {
 214+ # Look for the latest pristine revision...
 215+ if ( FlaggedRevs::pristineVersions() ) {
 216+ $prow = $db->selectRow(
 217+ array( 'flaggedrevs', 'revision' ),
 218+ self::selectFields(),
 219+ array_merge( $baseConds, array( 'fr_quality' => FR_PRISTINE ) ),
 220+ __METHOD__,
 221+ $options
 222+ );
 223+ # Looks like a plausible revision
 224+ $row = $prow ? $prow : $row;
 225+ }
 226+ if ( $row && $precedence === 'pristine' ) {
 227+ // we have what we want already
 228+ # Look for the latest quality revision...
 229+ } elseif ( FlaggedRevs::qualityVersions() ) {
 230+ // If we found a pristine rev above, this one must be newer...
 231+ $newerClause = $row
 232+ ? array( 'fr_rev_timestamp > '.$db->addQuotes( $row->fr_rev_timestamp ) )
 233+ : array();
 234+ $qrow = $db->selectRow(
 235+ array( 'flaggedrevs', 'revision' ),
 236+ self::selectFields(),
 237+ array_merge( $baseConds, array( 'fr_quality' => FR_QUALITY ), $newerClause ),
 238+ __METHOD__,
 239+ $options
 240+ );
 241+ $row = $qrow ? $qrow : $row;
 242+ }
220243 }
221 - if ( $row && $precedence === 'pristine' ) {
222 - // we have what we want already
223 - # Look for the latest quality revision...
224 - } elseif ( FlaggedRevs::qualityVersions() && $precedence !== 'latest' ) {
225 - // If we found a pristine rev above, this one must be newer...
226 - $newerClause = $row ? "fr_rev_id > {$row->fr_rev_id}" : "1 = 1";
227 - $qrow = $db->selectRow(
228 - array( 'flaggedrevs', 'revision' ),
229 - self::selectFields(),
230 - array( 'fr_page_id' => $pageId,
231 - 'fr_quality = ' . FR_QUALITY,
232 - $newerClause,
233 - 'rev_id = fr_rev_id',
234 - 'rev_page = fr_page_id',
235 - 'rev_deleted & ' . Revision::DELETED_TEXT => 0
236 - ),
237 - __METHOD__,
238 - $options
239 - );
240 - $row = $qrow ? $qrow : $row;
241 - }
242244 # Do we have one? If not, try the latest reviewed revision...
243245 if ( !$row ) {
244246 $row = $db->selectRow(
245247 array( 'flaggedrevs', 'revision' ),
246248 self::selectFields(),
247 - array( 'fr_page_id' => $pageId,
248 - 'rev_id = fr_rev_id',
249 - 'rev_page = fr_page_id',
250 - 'rev_deleted & ' . Revision::DELETED_TEXT => 0
251 - ),
 249+ $baseConds,
252250 __METHOD__,
253251 $options
254252 );
255 - if ( !$row ) return null;
 253+ if ( !$row ) {
 254+ return null;
 255+ }
256256 }
257257 $frev = new self( $row );
258258 $frev->mTitle = $title;
@@ -309,7 +309,7 @@
310310 );
311311 # Update flagged revisions table
312312 $dbw->replace( 'flaggedrevs',
313 - array( array( 'fr_page_id', 'fr_rev_id' ) ), $revRow, __METHOD__ );
 313+ array( array( 'fr_rev_id' ) ), $revRow, __METHOD__ );
314314 # Clear out any previous garbage...
315315 $dbw->delete( 'flaggedtemplates',
316316 array( 'ft_rev_id' => $this->getRevId() ), __METHOD__ );
@@ -353,8 +353,9 @@
354354 public static function selectFields() {
355355 return array_merge(
356356 Revision::selectFields(),
357 - array( 'fr_rev_id', 'fr_page_id', 'fr_user', 'fr_timestamp', 'fr_quality',
358 - 'fr_tags', 'fr_flags', 'fr_img_name', 'fr_img_sha1', 'fr_img_timestamp' )
 357+ array( 'fr_rev_id', 'fr_page_id', 'fr_rev_timestamp',
 358+ 'fr_user', 'fr_timestamp', 'fr_quality', 'fr_tags', 'fr_flags',
 359+ 'fr_img_name', 'fr_img_sha1', 'fr_img_timestamp' )
359360 );
360361 }
361362

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86179Overdue changes to `flaggedrevs` table:...aaron03:39, 16 April 2011

Status & tagging log