Topic: Same user appears 3 times in the online list
See: http://img359.imageshack.us/img359/9746 … tre9rr.jpg
I have _no_ idea what the problem could be.
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 bug reports → Same user appears 3 times in the online list
See: http://img359.imageshack.us/img359/9746 … tre9rr.jpg
I have _no_ idea what the problem could be.
I've had this happen as well. And it just seems to happen to one user in particular. I was going to try to track it down, but never did. The user said it didn't happen on an alternate account he had, but after completely switching user accounts, it still happens to the new account. Me thinks it's something on his end, but I can't figure out what it might be.
This problem also screws with the pagination, because when the joins for viewtopic occur, the post data gets tripled (or however many times the user appears to be online).
My theory: this happens when there's a bit of lag on the server. This means that when the player goes to login, it's slow, so he refreshes the page a couple times. All the SELECT queries end up getting done before the INSERT, so the online entry is inserted x number of times.
My idea to fix:
1. FIND
// Update the online list
if (!$pun_user['logged'])
$db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
REPLACE WITH
// Update the online list
if (!$pun_user['logged'])
$db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
FIND
// Update online list
if (!$pun_user['logged'])
$db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.time().')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
REPLACE WITH
// Update online list
if (!$pun_user['logged'])
$db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.time().')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
2. Add a compound unique index on user_id and ident.
Basically, this ensures that there will never be more then one online entry for the same user_id and ident.
+ add support for PostgreSQL and SQLite
How about something like this?
Or, instead of using replace into (which I'm told sucks for performance) change the select query in update_users_online() to order by ident, and when you go through, check if the ident is the same as the ident of the one before it (and if it is, we delete the entry)
Or, to be totally safe, you can change line 182 in index.php
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
to
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 group by user_id ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
That's only for display, it shouldn't help the multiple posts caused by it
I just came up with another possible fix (although I'm sure it's the worst fix): add a GROUP BY statement to the query, to group by the post ID. Thus, one copy of each post
I'm still having the problem (users appearing more than once in the user list, and their post being displayed more than once)... Are the fixes above safe?
The ones I posted? They should be
## Mod title: Users online today
##
## Mod version: 1.0.1
## Works on PunBB: 1.2.5
## Release date: 2005-06-14
## Author: Vincent Garnier a.k.a. vin100 (vin100@forx.fr)
##
## Description: This mod allow you to display a list of the registered
## users who was online during the day.
##
## Affected files: index.php
## lang/english/index.php
## lang/french/index.php
## style/imports/base.css
##
## Affects DB: No
##
##
## DISCLAIMER: Please note that "mods" are not officially supported by
## PunBB. Installation of this modification is done at your
## own risk. Backup your forum database and any and all
## applicable files before proceeding.
##
##
#
#---------[ 1. OPEN ]---------------------------------------------------------
#
index.php
#
#---------[ 2. FIND (line: 192) ]---------------------------------------------
#
$num_users = count($users);
#
#---------[ 3. AFTER, ADD ]---------------------------------------------------
#
// utilisateurs en ligne aujourd'hui
$date = getdate(time());
$todaystamp = mktime(0,0,0, $date['mon'], $date['mday'], $date['year']);
$result = $db->query('SELECT username, id, last_visit from '.$db->prefix.'users WHERE last_visit >= \''.$todaystamp.'\' ORDER by last_visit DESC') or error('Impossible de retrouver la liste des utilisateurs en ligne aujourd\'hui', __FILE__, __LINE__, $db->error());
$users_today = array();
while ($pun_user_online_today = $db->fetch_assoc($result))
$users_today[] .= "\n\t\t\t\t".'<dd><a href="profile.php?id='.$pun_user_online_today['id'].'" title="Dernière visite de '.$pun_user_online_today['username'].' : '.format_time($pun_user_online_today['last_visit']).'">'.$pun_user_online_today['username'].'</a>';
$num_users_today = count($users_today);
#
#---------[ 4. FIND (line: 193) ]---------------------------------------------
#
echo "\t\t\t\t".'<dd>'. $lang_index['Users online'].': <strong>'.$num_users.'</strong></dd>'."\n\t\t\t\t".'<dd>'.$lang_index['Guests online'].': <strong>'.$num_guests.'</strong></dd>'."\n\t\t\t".'</dl>'."\n";
#
#---------[ 5. REPLACE WITH ]-------------------------------------------------
#
echo "\t\t\t\t".'<dd>'.$lang_index['Users online'].': <strong>'.$num_users.'</strong></dd>'."\n\t\t\t\t".'<dd>'.$lang_index['Users today'].': <strong>'.$num_users_today.'</strong></dd>'."\n\t\t\t\t".'<dd>'.$lang_index['Guests online'].': <strong>'.$num_guests.'</strong></dd>'."\n\t\t\t".'</dl>'."\n";
#
#---------[ 6. FIND (line: 196-199) ]-----------------------------------------
#
if ($num_users > 0)
echo "\t\t\t".'<dl id="onlinelist" class= "clearb">'."\n\t\t\t\t".'<dt><strong>'.$lang_index['Online'].': </strong></dt>'."\t\t\t\t".implode(',</dd> ', $users).'</dd>'."\n\t\t\t".'</dl>'."\n";
else
echo "\t\t\t".'<div class="clearer"></div>'."\n";
#
#---------[ 7. AFTER, ADD ]---------------------------------------------------
#
// liste utilisateurs en ligne aujourd'hui
echo "\t\t\t".'<dl id="onlinetodaylist">'."\n\t\t\t\t".'<dt><strong>'.$lang_index['Online today'].': </strong></dt>';
if ($num_users_today > 0)
echo implode(',</dd> ', $users_today).'</dd>'."\n\t\t\t".'</dl>'."\n";
else
echo '<dd><em>aucun</em></dd>'."\n\t\t\t".'</dl>'."\n";
#
#---------[ 8. OPEN ]---------------------------------------------------------
#
style/imports/base.css
#
#---------[ 9. FIND (line: 223) ]---------------------------------------------
#
#onlinelist DD, #onlinelist DT, #brdmenu LI, DIV.linkst LI, DIV.linksb LI, DIV.postlinksb LI,
DIV.postfootright LI, UL.bblinks LI {
DISPLAY: inline;
HEIGHT: 0
}
#
#---------[ 10. REPLACE WITH ]------------------------------------------------
#
#onlinelist DD, #onlinelist DT, #onlinetodaylist DD, #onlinetodaylist DT,
#brdmenu LI, DIV.linkst LI, DIV.linksb LI, DIV.postlinksb LI,
DIV.postfootright LI, UL.bblinks LI {
DISPLAY: inline;
HEIGHT: 0
}
#
#---------[ 11. OPEN ]--------------------------------------------------------
#
lang/English/index.php
#
#---------[ 12. FIND (line: 4) ]----------------------------------------------
#
$lang_index = array(
#
#---------[ 13. AFTER, ADD ]--------------------------------------------------
#
'Online today' => 'Online today',
'Users today' => 'Registered users today',
#
#---------[ 14. OPEN ]--------------------------------------------------------
#
lang/French/index.php
#
#---------[ 15. FIND (line: 4) ]----------------------------------------------
#
$lang_index = array(
#
#---------[ 16. AFTER, ADD ]--------------------------------------------------
#
'Online today' => 'En ligne aujourd\'hui',
'Users today' => 'Membres aujourd\'hui',
#
#---------[ 17. SAVE/UPLOAD ]-------------------------------------------------
Err, what does that have to do with this topic?
BTW, it's not only the user appearing more than once in the user list, but his posts are displayed twice or more too... Do that fix it too?
Yes, they're caused by the same thing
I applied smarty's patch. Is this gonna be fixed in punbb's next version? :]
Yes.
Where do i have to change the rows above?
I coldn't find them in the index.php or the footer.php
My fix was in functions.php
smartys, i applied your fix a while ago and today the bug happened again, the user posted and it listed it twice.
You added a compound unique index on user_id and ident on the online table?
i did the fix you listed above under:
How about something like this?
in functions.php
In other words, no, since that's just code editing
For it to work in MySQL you need to add the index. I'll write out the syntax if you want
I'll write out the syntax if you want
that would be great
alter table prefixonline add unique index unique_online_idx (user_id,ident)
Replace prefix with your db_prefix.
That should work, paste me the error if it doesn't
PunBB Forums → PunBB 1.2 bug reports → Same user appears 3 times in the online list
Powered by PunBB, supported by Informer Technologies, Inc.