From: Marius Hoch Date: Sun, 23 Feb 2014 20:47:48 +0000 (+0100) Subject: Make SiteStats (re)initializing more sane X-Git-Tag: 1.31.0-rc.0~16845 X-Git-Url: http://git.cyclocoop.org/%27.%28%24current%20%3E%202?a=commitdiff_plain;h=d8c03733718ac9eedabad7e4fa569426a56acc31;p=lhc%2Fweb%2Fwiklou.git Make SiteStats (re)initializing more sane Don't set ss_active_users back to its default in SiteStatsInit::refresh. Also remove SiteStatsInit::update and make refresh() protected. Also don't consider ss_active_users in SiteStats::isSane as that value isn't going to be fixed by the following SiteStatsInit::refresh call. Change-Id: I268599be96106e1175fdf9750a2adc9468ebc93c --- diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 0df6d907cc..6e2b5fa180 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -240,7 +240,6 @@ class SiteStats { 'ss_good_articles', 'ss_total_pages', 'ss_users', - 'ss_active_users', 'ss_images', ) as $member ) { if ( $row->$member > 2000000000 || $row->$member < 0 ) { @@ -360,7 +359,6 @@ class SiteStatsInit { * - Boolean: whether to use the master DB * - DatabaseBase: database connection to use * @param array $options of options, may contain the following values - * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false) * - views Boolean: when true, do not update the number of page views (default: true) * - activeUsers Boolean: whether to update the number of active users (default: false) */ @@ -381,12 +379,7 @@ class SiteStatsInit { $counter->views(); } - // Update/refresh - if ( $options['update'] ) { - $counter->update(); - } else { - $counter->refresh(); - } + $counter->refresh(); // Count active users if need be if ( $options['activeUsers'] ) { @@ -395,39 +388,21 @@ class SiteStatsInit { } /** - * Update the current row with the selected values - */ - public function update() { - list( $values, $conds ) = $this->getDbParams(); - $dbw = wfGetDB( DB_MASTER ); - $dbw->update( 'site_stats', $values, $conds, __METHOD__ ); - } - - /** - * Refresh site_stats. Erase the current record and save all - * the new values. + * Refresh site_stats. */ - public function refresh() { - list( $values, $conds, $views ) = $this->getDbParams(); - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'site_stats', $conds, __METHOD__ ); - $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ ); - } - - /** - * Return three arrays of params for the db queries - * @return Array - */ - private function getDbParams() { + protected function refresh() { $values = array( + 'ss_row_id' => 1, 'ss_total_edits' => $this->mEdits, 'ss_good_articles' => $this->mArticles, 'ss_total_pages' => $this->mPages, 'ss_users' => $this->mUsers, - 'ss_images' => $this->mFiles + 'ss_images' => $this->mFiles, + ) + ( + $this->mViews ? array( 'ss_total_views' => $this->mViews ) : array() ); - $conds = array( 'ss_row_id' => 1 ); - $views = array( 'ss_total_views' => $this->mViews ); - return array( $values, $conds, $views ); + + $dbw = wfGetDB( DB_MASTER ); + $dbw->upsert( 'site_stats', $values, array( 'ss_row_id' ), $values, __METHOD__ ); } }