Permalink
Browse files

Cache the user count and newest user information to show on the index…

…. Suggested by Adaur/Visman.
  • Loading branch information...
reines committed Feb 20, 2011
1 parent 01d860a commit 17c131a7580b0db39250cd9ecea56c8d5423be68
Showing with 75 additions and 9 deletions.
  1. +10 −4 extern.php
  2. +29 −0 include/cache.php
  3. +10 −5 index.php
  4. +8 −0 login.php
  5. +12 −0 profile.php
  6. +6 −0 register.php
View
@@ -518,11 +518,17 @@ function output_html($feed)
require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
// Collect some statistics from the database
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php'))
include FORUM_CACHE_DIR.'cache_users_info.php';
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
if (!defined('PUN_USERS_INFO_LOADED'))
{
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
require FORUM_CACHE_DIR.'cache_users_info.php';
}
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
View
@@ -236,6 +236,35 @@ function generate_stopwords_cache()
}
//
// Load some information about the latest registered users
//
function generate_users_info_cache()
{
global $db;
$stats = array();
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
// Output stopwords as PHP code
$fh = @fopen(FORUM_CACHE_DIR.'cache_users_info.php', 'wb');
if (!$fh)
error('Unable to write users info cache file to cache directory. Please make sure PHP has write access to the directory \''.pun_htmlspecialchars(FORUM_CACHE_DIR).'\'', __FILE__, __LINE__);
fwrite($fh, '<?php'."\n\n".'define(\'PUN_USERS_INFO_LOADED\', 1);'."\n\n".'$stats = '.var_export($stats, true).';'."\n\n".'?>');
fclose($fh);
if (function_exists('apc_delete_file'))
@apc_delete_file(FORUM_CACHE_DIR.'cache_users_info.php');
}
//
// Delete all feed caches
//
View
@@ -171,13 +171,18 @@
else
echo '<div id="idx0" class="block"><div class="box"><div class="inbox"><p>'.$lang_index['Empty board'].'</p></div></div></div>';
// Collect some statistics from the database
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php'))
include FORUM_CACHE_DIR.'cache_users_info.php';
if (!defined('PUN_USERS_INFO_LOADED'))
{
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
generate_users_info_cache();
require FORUM_CACHE_DIR.'cache_users_info.php';
}
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
View
@@ -65,8 +65,16 @@
// Update the status if this is the first time the user logged in
if ($cur_user['group_id'] == PUN_UNVERIFIED)
{
$db->query('UPDATE '.$db->prefix.'users SET group_id='.$pun_config['o_default_user_group'].' WHERE id='.$cur_user['id']) or error('Unable to update user status', __FILE__, __LINE__, $db->error());
// Regenerate the users info cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
}
// Remove this users guest entry from the online list
$db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape(get_remote_address()).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());
View
@@ -444,6 +444,12 @@
$db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
// Regenerate the users info cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
$result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$new_group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
$new_group_mod = $db->result($result);
@@ -600,6 +606,12 @@
// Delete user avatar
delete_avatar($id);
// Regenerate the users info cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
redirect('index.php', $lang_profile['User delete redirect']);
}
View
@@ -159,6 +159,12 @@
$db->query('INSERT INTO '.$db->prefix.'users (username, group_id, password, email, email_setting, timezone, dst, language, style, registered, registration_ip, last_visit) VALUES(\''.$db->escape($username).'\', '.$intial_group_id.', \''.$password_hash.'\', \''.$db->escape($email1).'\', '.$email_setting.', '.$timezone.' , '.$dst.', \''.$db->escape($language).'\', \''.$pun_config['o_default_style'].'\', '.$now.', \''.get_remote_address().'\', '.$now.')') or error('Unable to create user', __FILE__, __LINE__, $db->error());
$new_uid = $db->insert_id();
// Regenerate the users info cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
// If the mailing list isn't empty, we may need to send out some alerts
if ($pun_config['o_mailing_list'] != '')
{

0 comments on commit 17c131a

Please sign in to comment.