<?php
+/**
+ * Accessors and mutators for the site-wide statistics.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
/**
* Static accessor class for site_stats and related things
$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;
}
$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 );
/**
* @param $type string
* @param $sign string ('+' or '-')
- * @return void
+ * @return string
*/
private function getTypeCacheKey( $type, $sign ) {
return wfMemcKey( 'sitestatsupdate', 'pendingdelta', $type, $sign );
/**
* Reduce pending delta counters after updates have been applied
- * @param Array Result of getPendingDeltas(), used for DB update
+ * @param Array $pd Result of getPendingDeltas(), used for DB update
* @return void
*/
protected function removePendingDeltas( array $pd ) {