1

Topic: New posts in topics.

As it is now it's based on the time you were last logged in and all topics with posts after that time is marked as "unread". Is there any possibility that you'll change the forum so that if I read a topic it'll immediately be marked as "read". Hope you know what I mean. I ask because some of my users would appreciate it very much.

Re: New posts in topics.

Yeah, just like vbulletin.

Re: New posts in topics.

This has been requested before. However, it's not something that is implemented in an hour. I have yet to see a fast, scalable and pretty solution to the problem. We'll see. I'll put it on the wishlist for 1.2 :)

Muggen wrote:

Yeah, just like vbulletin.

By that you mean vBulletin 3 right? vBulletin 2.x works almost identical to the way PunBB works.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

4

Re: New posts in topics.

I understand that it's nothing you do in an afternoon. Thanks for putting it on the wishlist and I hope that it'll be a future feature of PunBB.

Re: New posts in topics.

yeah, i got users saying it is very annoying that the posts are not marked as read. And if they post their own post is marked as unread.... but whatever smile i just tell they have to live with it wink
i'll just patiently wait till the feature is implemented smile

6 (edited by Paul 2004-02-17 15:02)

Re: New posts in topics.

I would have thought this would be something very difficult to implement. The reason being that, as far as I can tell, PunBB is totally indifferent as to whether a topic has been read; it is only concerned with whether or not the topic is dated after the users last visit. To distinguish whether a particular user has read a particular topic would seem to require a whole raft full of new code/tables/fields.

Having the time of last visit updated during a visit would cause the opposite problem. Imagine there are 10 new topics since last visit. You read one topic and then the timestamp is updated. The result is it would now appear that there were no new topics since last visit. That would be a lot worse than the current situation.

7

Re: New posts in topics.

You're right, but how's that normally solved? I can hardly imagine keeping a field for every user on a topic, or for every topic on a user... never thought of this problem before.

8 (edited by Paul 2004-02-17 14:13)

Re: New posts in topics.

It's difficult to think of a decent solution because it seems that somewhere there has to be a list of what topics a particular user has not read and everytime the user reads a topic the list has to be updated. I can't see that it could possibly be implemented through the database. If a user has not visited for serveral months the list could be thousands of posts long.

The only thing I can think of is that when a user logs in a txt/dat file is created listing topic id's of posts since last visit. Everytime a topic is read the list is rewritten minus the recently read post. When the user leaves the file is deleted.

9

Re: New posts in topics.

Ugly ugly solutions. Well, if there's not a very elegant and execution-quick way to solve this one, I think it's better left undone.

Re: New posts in topics.

Well if I would do a similar thing, I would have a 'heap' table (only stored in memory, not on disk, more speed, and if server goes down it's no biggie), where the users read posts are logged for this session (prolly an age thing with timestamp) ... and then load these 'read' ones into an array when looking on a forum, and if the topic would be labelled like unread, it checks in the array if this has been read in this session, in that case, skip the 'unread' notice... othervise show it ...

alot of scripting/testing to make it neat and slim ... but I would probably use that method if I would do something similar ... as it's the 'cleanest' method I so far have thought of wink

11

Re: New posts in topics.

Hmmm well, every situation has its pros and cons, but in this case, I'd say there's no way you can keep that in a server's memory, although it could be a session object (although I find that a lousy solution since it adds innecessary load to the server). Or a variable passed to the browser... I list all new topics since last visit (just like now at session start), and send you the id's in a cookie, on the next hit, I'll first add all new posts to the cookie, then substract the one you're requesting and show the rest as new when you hit the topic page again.
I think that's the best I could come up with, and I'm not sure it's even good.

12 (edited by Paul 2004-02-17 16:40)

Re: New posts in topics.

I have just realised I'm a moron (don't all applaud at once). You don't need a list of unread posts, you just need a list of posts that have been read during a particular visit which starts off as blank and gets added to everytime a post is read. To be marked as unread/new a post would have to not only be newer than the last visit time but also NOT appear in the list of posts read during that visit. Since the list of posts read during a particular visit is unlikely to be more than a few dozen even on a large forum it could be done through the database or an array. When a member leaves the list of read posts is simply reset to nothing. The fact that there are hundreds or thousands of unread posts since somebody's last visit won't make a blind bit of difference because it is only read posts that are being listed. I think this is the idea FrankH had only it took me till now to realise it.

13 (edited by Frank H 2004-02-17 17:19)

Re: New posts in topics.

Paul wrote:

I think this is the idea FrankH had only it took me till now to realise it.

Heh, yep, store as little as possible wink

MarcB: memory isn't that expencive wink
nah, really, if you check into it... what this table would need to store, is like 30 bytes per read post for that session ... (user id = int(10), topic id = int(10), unix timestamp =int(10) == 30bytes) ... and if you would have a whooping 64MB table, that would give the possibility to have 2'236'962 read posts in store for that session, and considering that the cookie will default time out in like 10 minutes or so, you either should have a very quick hand or an extreme wide audience ... just over 3700 pageviews/s (Edit: forum pageviews that is)

14

Re: New posts in topics.

Frank H: can leave an item in memory with PHP?

Re: New posts in topics.

Ok, first of all. People all over the world have been using vBulletin 2 (which works just like PunBB) for years now and I have never ever seen anyone "complain" about it there. What's up?

There are known implementations, but they are all ugly. The most common implementation is storing the topics you've read in an array that is then serialized and saved in a cookie. I believe this is also the simplest way of doing it. There are issues though. How long should you wait before a topic is considered unread again? How many topics should the forum keep track of? If your visiting a large forum with topic IDs like 231874 and you read 200 topics, that cookie will become quite large (about 2000 bytes).

The second possible solution is using the database like Frank H suggested. However, it would mean at least two to three more queries (SELECT read topics, UPDATE new topics and DELETE old topics) for every single page view. Sure, one could use a HEAP table that will speed it up, but there's still the general communication overhead when talking to the database. Also, HEAP tables are only supported by MySQL and most hosts have set MAX_ROWS to a low value so that their customers don't use up too much memory.

The jury's still out on this one.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: New posts in topics.

MarcB wrote:

Frank H: can leave an item in memory with PHP?

No, not without third party extensions to PHP.

Edit: See shmop.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: New posts in topics.

Frank H wrote:

nah, really, if you check into it... what this table would need to store, is like 30 bytes per read post for that session ... (user id = int(10), topic id = int(10), unix timestamp =int(10) == 30bytes)

Actually, it's only 12 bytes. An integer takes up 4 bytes (32 bits).

Frank H wrote:

2'236'962 read posts in store for that session, and considering that the cookie will default time out in like 10 minutes or so, you either should have a very quick hand or an extreme wide audience ... just over 3700 pageviews/s (Edit: forum pageviews that is)

MAX_ROWS will limit the number of rows in a HEAP table long before that.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: New posts in topics.

Rickard wrote:

MAX_ROWS will limit the number of rows in a HEAP table long before that.

True

but I must say I dont' have any trouble with how it is now ... as it makes PunBB what it is (faster & smaller)

I don't have such a bad memory that I don't know that I have or haven't read a post, and if I accidently click one again ... it's no big deal wink
I jsut start from the 'bottom' of the unread messages .... and when I have replied to it ... then I know I have read it aswell wink

19

Re: New posts in topics.

Yep, since we can easily see the date of last post... smile

20

Re: New posts in topics.

No problem here either. I think we were just throwing ideas around.

21 (edited by Yann 2004-05-23 18:11)

Re: New posts in topics.

waiiiit i think I got it... it seems to work..  should be ready tonight smile (with only one small cookie, and one db query) Ok, here is a beginning; shows unread threads, but not unread forums, is not that perfect but seems to work:

add this to viewtopic.php, at the beginning:

if ($_COOKIE['unreadtopicscookie'] != '') {
    $unreadtopics = array();
    $unreadtopics = unserialize(stripslashes($_COOKIE['unreadtopicscookie']));
    unset($unreadtopics[array_search($_GET['id'], $unreadtopics)]);
    setcookie('unreadtopicscookie', serialize($unreadtopics), time()+60*60*24*335); /* One year cookie*/
}

and add this to viewforum.php (below the two includes):

if ($_COOKIE['unreadtopicscookie'] != '') {
    $unreadtopics = array();
    $unreadtopics = unserialize(stripslashes($_COOKIE['unreadtopicscookie']));

    $result = $db->query('SELECT id , last_post FROM '.$db->prefix.'topics') or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

    while ($row = $db->fetch_row($result))
    if ($row[1]>$cur_user['last_visit'] && !in_array($row[0], $unreadtopics))
        array_push($unreadtopics, $row[0]);

    setcookie('unreadtopicscookie', serialize($unreadtopics), time()+60*60*24*335); /* One year cookie*/
} else {
    $unreadtopics = array();
}       

And finally in viewforum.php, where the test if the topic is read or not (should be approximatively at line 165), replace the condition with:
if (!$cookie['is_guest'] && in_array($cur_topic['id'], $unreadtopics) && $cur_topic['moved_to'] == null)

I'll try to cleanup all that stuff, and make it work in the listing of the forums, too... help would be much appreciated.
++

I forgot, turn Visit timeout to 0 in the admin panel.
BTW, in misc.php, add :
setcookie('unreadtopicscookie', '', time()+60*60*24*335);
in the else if ($action == 'markread') statement.

Re: New posts in topics.

I don't like this part:

$result = $db->query('SELECT id , last_post FROM '.$db->prefix.'topics') or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

while ($row = $db->fetch_row($result))
    if ($row[1]>$cur_user['last_visit'] && !in_array($row[0], $unreadtopics))
        array_push($unreadtopics, $row[0]);

Selecting all topics and manually going through them all! What if the forum has 50000 topics?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

23 (edited by Yann 2004-05-23 14:51)

Re: New posts in topics.

mmmh, in fact alll what I need are the newest topics... i'll try adding a where clause.
NB: is it possible to discuss with you via irc, icq, other? might be easier.
+


$result = $db->query('SELECT id , last_post FROM '.$db->prefix.'topics where last_post>'.$cur_user['last_visit']) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

while ($row = $db->fetch_row($result))
    if (!in_array($row[0], $unreadtopics))
        array_push($unreadtopics, $row[0]);


better so?

Re: New posts in topics.

I think the Improved New Message mod needs less CPU

25

Re: New posts in topics.

mmh... not sure.. you are calling a function for each topic, i'm doing one sql query... moreover, it might be possible to do the same without that query, using a query that is already done later... and i'm using only one cookie big_smile