diff --git a/admin/admin_forums.php b/admin/admin_forums.php index 4354a59e2..f37c986e7 100644 --- a/admin/admin_forums.php +++ b/admin/admin_forums.php @@ -472,6 +472,7 @@ if ($mode) { fix_orphan_sf(); \TorrentPier\Legacy\Group::update_user_level('all'); $datastore->update('cat_forums'); + $datastore->update('stats'); CACHE('bb_cache')->rm(); bb_die($lang['FORUMS_UPDATED'] . '

' . sprintf($lang['CLICK_RETURN_FORUMADMIN'], '', '') . '

' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', '')); diff --git a/admin/index.php b/admin/index.php index 5628bd95e..844336e9c 100644 --- a/admin/index.php +++ b/admin/index.php @@ -9,6 +9,12 @@ require __DIR__ . '/pagestart.php'; +// Statistics +if (!$stats = $datastore->get('stats')) { + $datastore->update('stats'); + $stats = $datastore->get('stats'); +} + // Generate relevant output if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $module = []; @@ -71,9 +77,9 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { ]); // Get forum statistics - $total_posts = get_db_stat('postcount'); - $total_users = get_db_stat('usercount'); - $total_topics = get_db_stat('topiccount'); + $total_posts = $stats['postcount']; + $total_topics = $stats['topiccount']; + $total_users = $stats['usercount']; $start_date = bb_date($bb_cfg['board_startdate']); $boarddays = (TIMENOW - $bb_cfg['board_startdate']) / 86400; diff --git a/library/includes/datastore/build_stats.php b/library/includes/datastore/build_stats.php index 2520af93b..bd8ef8a4e 100644 --- a/library/includes/datastore/build_stats.php +++ b/library/includes/datastore/build_stats.php @@ -20,7 +20,7 @@ $row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM " . BB_USERS . " WHERE $data['usercount'] = commify($row['usercount']); // newestuser -$row = DB()->fetch_row("SELECT user_id, username, user_rank FROM " . BB_USERS . " WHERE user_active = 1 ORDER BY user_id DESC LIMIT 1"); +$row = DB()->fetch_row("SELECT user_id, username, user_rank FROM " . BB_USERS . " WHERE user_active = 1 AND user_id NOT IN(" . EXCLUDED_USERS . ") ORDER BY user_id DESC LIMIT 1"); $data['newestuser'] = $row; // post/topic count diff --git a/library/includes/functions.php b/library/includes/functions.php index d7a5555da..2a3eef73a 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -932,48 +932,6 @@ function bb_update_config($params, $table = BB_CONFIG) bb_get_config($table, true, true); } -function get_db_stat($mode) -{ - $sql = null; - switch ($mode) { - case 'usercount': - $sql = "SELECT COUNT(user_id) AS total FROM " . BB_USERS; - break; - - case 'newestuser': - $sql = "SELECT user_id, username FROM " . BB_USERS . " WHERE user_id <> " . GUEST_UID . " ORDER BY user_id DESC LIMIT 1"; - break; - - case 'postcount': - case 'topiccount': - $sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total FROM " . BB_FORUMS; - break; - } - - if (!($result = DB()->sql_query($sql))) { - return false; - } - - $row = DB()->sql_fetchrow($result); - - switch ($mode) { - case 'usercount': - return $row['total']; - break; - case 'newestuser': - return $row; - break; - case 'postcount': - return $row['post_total']; - break; - case 'topiccount': - return $row['topic_total']; - break; - } - - return false; -} - function clean_username($username) { $username = mb_substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25, 'UTF-8');