Merge "Fix trailing whitespace (and mixed spaces) in XSD files"
[lhc/web/wiklou.git] / includes / SiteStats.php
index fec24e9..10aed9c 100644 (file)
@@ -286,14 +286,13 @@ class SiteStatsUpdate implements DeferrableUpdate {
                        $this->doUpdatePendingDeltas();
                } else {
                        $dbw = wfGetDB( DB_MASTER );
-                       // Need a separate transaction because this a global lock
-                       $dbw->begin( __METHOD__ );
 
                        $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID
                        if ( $rate ) {
                                // Lock the table so we don't have double DB/memcached updates
-                               if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
-                                       $dbw->commit( __METHOD__ );
+                               if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
+                                       || !$dbw->lock( $lockKey, __METHOD__, 1 ) // 1 sec timeout
+                               ) {
                                        $this->doUpdatePendingDeltas();
                                        return;
                                }
@@ -307,6 +306,9 @@ class SiteStatsUpdate implements DeferrableUpdate {
                                $this->images   += ( $pd['ss_images']['+'] - $pd['ss_images']['-'] );
                        }
 
+                       // Need a separate transaction because this a global lock
+                       $dbw->begin( __METHOD__ );
+
                        // Build up an SQL query of deltas and apply them...
                        $updates = '';
                        $this->appendUpdate( $updates, 'ss_total_views', $this->views );