From 991bb4c01613be2e16f7bc90340c6832a70a77c1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 1 Sep 2008 19:22:28 +0000 Subject: [PATCH] * Remove mysql var and move field init to updaters.inc --- includes/SiteStats.php | 2 +- maintenance/archives/patch-ss_active_users.sql | 3 --- maintenance/updaters.inc | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 5ae3203909..e209cc2163 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -265,7 +265,7 @@ class SiteStatsUpdate { $dbw->begin(); $dbw->update( 'site_stats', array( 'ss_active_users' => intval($activeUsers) ), - array('1 = 1'), __METHOD__, array( 'LIMIT' => 1 ) + array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 ) ); $dbw->commit(); } diff --git a/maintenance/archives/patch-ss_active_users.sql b/maintenance/archives/patch-ss_active_users.sql index 7143905248..a583cdc8c6 100644 --- a/maintenance/archives/patch-ss_active_users.sql +++ b/maintenance/archives/patch-ss_active_users.sql @@ -1,6 +1,3 @@ -- More statistics, for version 1.14 ALTER TABLE /*$wgDBprefix*/site_stats ADD ss_active_users bigint default '-1'; -SELECT @activeusers := COUNT( DISTINCT rc_user_text ) FROM /*$wgDBprefix*/recentchanges -WHERE rc_user != 0 AND rc_bot = 0 AND rc_log_type != 'newusers'; -UPDATE /*$wgDBprefix*/site_stats SET ss_active_users=@activeusers; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index e22412c1f5..0533b66a6f 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -146,6 +146,7 @@ $wgMysqlUpdates = array( // 1.14 array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ), + array( 'do_active_users_init' ) ); @@ -1027,6 +1028,23 @@ function do_stats_init() { } } +function do_active_users_init() { + global $wgDatabase; + $activeUsers = $wgDatabase->selectField( 'site_stats', 'ss_active_users', + array( 'ss_row_id' => 1 ), __METHOD__ ); + if( $activeUsers === -1 ) { + $activeUsers = $wgDatabase->selectField( 'recentchanges', + 'COUNT( DISTINCT rc_user_text )', + array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__ + ); + $wgDatabase->update( 'site_stats', + array( 'ss_active_users' => intval($activeUsers) ), + array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 ) + ); + } + echo( "...ss_active_users user count set...\n" ); +} + function purge_cache() { global $wgDatabase; # We can't guarantee that the user will be able to use TRUNCATE, -- 2.20.1