Improved ActiveUsers cache staleness estimates
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 24 Apr 2015 07:19:17 +0000 (00:19 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 24 Apr 2015 07:23:34 +0000 (00:23 -0700)
Change-Id: Iddbdd90ff91d65f93dc51da0c8a5c0d4d0ab219f

includes/specials/SpecialActiveusers.php

index 5e2ee1c..047e941 100644 (file)
@@ -267,21 +267,24 @@ class SpecialActiveUsers extends SpecialPage {
                $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
                        array( 'activeusers-intro', $this->getLanguage()->formatNum( $days ) ) );
 
-               // Get the timestamp of the last cache update
+               // Mention the level of cache staleness...
                $dbr = wfGetDB( DB_SLAVE, 'recentchanges' );
-               $cTime = $dbr->selectField( 'querycache_info',
-                       'qci_timestamp',
-                       array( 'qci_type' => 'activeusers' )
-               );
-
-               $secondsOld = $cTime
-                       ? time() - wfTimestamp( TS_UNIX, $cTime )
-                       : $days * 86400; // fully stale :)
-
-               if ( $secondsOld > 0 ) {
-                       // Mention the level of staleness
-                       $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl',
+               $rcMax = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)' );
+               if ( $rcMax ) {
+                       $cTime = $dbr->selectField( 'querycache_info',
+                               'qci_timestamp',
+                               array( 'qci_type' => 'activeusers' )
+                       );
+                       if ( $cTime ) {
+                               $secondsOld = wfTimestamp( TS_UNIX, $rcMax ) - wfTimestamp( TS_UNIX, $cTime );
+                       } else {
+                               $rcMin = $dbr->selectField( 'recentchanges', 'MIN(rc_timestamp)' );
+                               $secondsOld = time() - wfTimestamp( TS_UNIX, $rcMin );
+                       }
+                       if ( $secondsOld > 0 ) {
+                               $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl',
                                $this->getLanguage()->formatDuration( $secondsOld ) );
+                       }
                }
 
                $up = new ActiveUsersPager( $this->getContext(), null, $par );