r24176 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24175‎ | r24176 | r24177 >
Date:19:48, 16 July 2007
Author:simetrical
Status:old
Tags:
Comment:
(bug 4650) Added various sanity checks to site stats generation.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SiteStats.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SiteStats.php
@@ -32,19 +32,19 @@
3333 static function loadAndLazyInit() {
3434 wfDebug( __METHOD__ . ": reading site_stats from slave\n" );
3535 $row = self::doLoad( wfGetDB( DB_SLAVE ) );
36 -
37 - if( $row === false ) {
38 - // Might have just been initialzed during this request?
39 - wfDebug( __METHOD__ . ": site_stats missing on slave\n" );
 36+
 37+ if( !self::isSane( $row ) ) {
 38+ // Might have just been initialized during this request? Underflow?
 39+ wfDebug( __METHOD__ . ": site_stats damaged or missing on slave\n" );
4040 $row = self::doLoad( wfGetDB( DB_MASTER ) );
4141 }
4242
43 - if( $row === false ) {
 43+ if( !self::isSane( $row ) ) {
4444 // Normally the site_stats table is initialized at install time.
45 - // Some manual construction scenarios may leave the table empty,
46 - // however, for instance when importing from a dump into a clean
47 - // schema with mwdumper.
48 - wfDebug( __METHOD__ . ": initializing empty site_stats\n" );
 45+ // Some manual construction scenarios may leave the table empty or
 46+ // broken, however, for instance when importing from a dump into a
 47+ // clean schema with mwdumper.
 48+ wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" );
4949
5050 global $IP;
5151 require_once "$IP/maintenance/initStats.inc";
@@ -56,8 +56,8 @@
5757 $row = self::doLoad( wfGetDB( DB_MASTER ) );
5858 }
5959
60 - if( $row === false ) {
61 - wfDebug( __METHOD__ . ": init of site_stats failed o_O\n" );
 60+ if( !self::isSane( $row ) ) {
 61+ wfDebug( __METHOD__ . ": site_stats persistently nonsensical o_O\n" );
6262 }
6363 return $row;
6464 }
@@ -114,6 +114,27 @@
115115 return $pageCount[$ns];
116116 }
117117
 118+ /** Is the provided row of site stats sane, or should it be regenerated? */
 119+ private static function isSane( $row ) {
 120+ if(
 121+ $row === false
 122+ or $row->ss_good_articles < $row->ss_total_pages
 123+ or $row->ss_total_edits < $row->ss_total_pages
 124+ or $row->ss_users < $row->ss_admins
 125+ ) {
 126+ return false;
 127+ }
 128+ // Now check for underflow/overflow
 129+ foreach( array( 'total_views', 'total_edits', 'good_articles',
 130+ 'total_pages', 'users', 'admins', 'images' ) as $member ) {
 131+ if(
 132+ $row->{"ss_$member"} > 2000000000
 133+ or $row->{"ss_$member"} < 0
 134+ ) {
 135+ return false;
 136+ }
 137+ }
 138+ }
118139 }
119140
120141
Index: trunk/phase3/RELEASE-NOTES
@@ -308,6 +308,7 @@
309309 * Don't allow retrieving non-JavaScript/CSS pages with "text/css" or "text/javascript"
310310 MIME types
311311 * (bug 1629) Stop section edit links from being shoved down by other floats
 312+* (bug 4650) Keep impossibly large/small counts off Special:Statistics
312313
313314 == API changes since 1.10 ==
314315

Follow-up revisions

RevisionCommit summaryAuthorDate
r24215Merged revisions 24095-24212 via svnmerge from...david21:19, 17 July 2007

Status & tagging log