Marking of topics/forums logic (technical)

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Get Involved
Post Reply
.Johnny
Registered User
Posts: 7
Joined: Wed May 23, 2007 8:28 am

Marking of topics/forums logic (technical)

Post by .Johnny »

Hi,

I'm working on some integration of phpBB with another website. What it will do basically is share login cookies and procedures (i've got that working) and display a list of the newest topics.
Together with the list of topics, I want to display the ones that are read different from the unread ones. Unfortunatly that part has changed from phpBB2 to 3 significantly and I don't understand what it is doing exactly. When are topics marked read?

Some logic I think I found thusfar:

topics marking is no longer stored in a cookie, but in a "_track" table for both topics as forums. in those tables are "mark_time" fields.
I suppose a mark_time of a topic in the end is defined by either the forum or the topic mark_time, depending which value is bigger.

One of the bigger changes I quitte can't get a grip on is that topics now remain unread, even though you log-out and back in again. I understand conceptualy what it does, but I don't really see how this is computed from the data, because some older topics below a certain threshold are read whilst newer topics arent. what is that treshold? As said before, I would like to mimic this to the frontpage, but don't know yet how to decide for a topic that has no new posts since user_lastvisit. What is the field to determine then? is it user_lastmark? when is that field updated?

fields I've found:
_users
->user_lastvisit
->user_lastmark
(where did user_session_time go?)

_topics_track
->mark_time

_forums_track
->mark_time

I'm a bit lost here; any help would be great!
User avatar
Eelke
Registered User
Posts: 2903
Joined: Thu Dec 20, 2001 8:00 am
Location: NL, Bussum
Name: Eelke Blok
Contact:

Re: Marking of topics/forums logic (technical)

Post by Eelke »

.Johnny wrote:some older topics below a certain threshold are read whilst newer topics arent. what is that treshold?
Can't you find out by examining the code that determines read and unread status of topics? Either this would contain some "hard" fallback value, or it just involves the mark times you already noticed. Personally, I expect the latter, because you will need some kind of cleanup mechanism anyway; if a particular user never marks forums read - at which time I would expect individual topic mark times to be cleaned up - then the tables could fill up with individual topic mark times. So, some specific action to also limit the number of unread topics shown when they need to be displayed seems to be redundant.

I'd say a good time to do some housekeeping regarding read status cleanup is at session start; mark all forums read at a certain time period before login time and remove all individual topic mark times before that time.

Anyway, interesting stuff, if things become a little more clear, this might make a nice HOWTO.
.Johnny
Registered User
Posts: 7
Joined: Wed May 23, 2007 8:28 am

Re: Marking of topics/forums logic (technical)

Post by .Johnny »

Yeah, ofcourse I could reverse engineer the whole thing, but I was hoping someone knows all the rationale. I mean; someone coded this, so I hope theres some documentation about this somewhere. Although its currently not available online.
User avatar
Eelke
Registered User
Posts: 2903
Joined: Thu Dec 20, 2001 8:00 am
Location: NL, Bussum
Name: Eelke Blok
Contact:

Re: Marking of topics/forums logic (technical)

Post by Eelke »

Fair enough. Just remember that whoever coded it may be busy doing other things, so finding out yourself may be faster.
Acyd Burn
Consultant
Consultant
Posts: 5830
Joined: Wed Dec 05, 2001 8:31 pm
Location: Behind You
Name: Meik Sievertsen

Re: Marking of topics/forums logic (technical)

Post by Acyd Burn »

What is the problem here? Just use the mechanism we used within viewtopic if you want to have unread/read information for posts, viewforum if for topics. If you need the read/unread status information from several forums merged use the mechanism from the user control panel (bookmarked topics, watched topics...).

Generally there are several systems, depending on what the admin defined. DB last read tracking and cookie last read tracking (including/excluding guest read tracking - which is always cookie based).

user_lastmark defines the time the user marked all forums read - we can assume everything < this time is read.
forums_track holds the last mark time forum-based - so we can assume everything < this time within the forum is read.
topics_track is holding the last mark time for a specific topic - so we can assume everything < this time within the topic is read.

Now, combining the three we are able to tell which forums, topics, posts are read or unread while being able to not waste db space - for example if you mark all forums read the topics_track and forums_track entries will be emptied for your user account.

Granted, the mechanism could be made much simpler (maybe by calling a single function) - at the moment it is joining the correct tables, calling get_topic_tracking()/get_complete_topic_tracking() and then assigning true/false based on topic tracking info and the last post time.
.Johnny
Registered User
Posts: 7
Joined: Wed May 23, 2007 8:28 am

Re: Marking of topics/forums logic (technical)

Post by .Johnny »

Thanks, that is very helpful!

The reason I can't rely on phpBB functions for listing all this is AJAX. On the frontpage of the website I use ajax to auto-update the list of topics. This means you get into a whole lot of synchronisation issues (b/c it uses asynchronic mechanisms) and then calling phpBB functions would cause multiple sessions created for one user. Thats why I created a "session_lazy" function which will try to establish whether there is a session but never will create one. Afaik there's no way to do this with phpBB code, as it will always create a session if there is none.

it's a bit off-topic from what is I was asking, but it might clarify why I can't rely on most of the phpBB functions. It would be useful to have some api's where you can just throw in some user->data (like session_user_id) and retrieve a list of topics with their read status. But in fact, thats just what i'm hacking together right now.
User avatar
Eelke
Registered User
Posts: 2903
Joined: Thu Dec 20, 2001 8:00 am
Location: NL, Bussum
Name: Eelke Blok
Contact:

Re: Marking of topics/forums logic (technical)

Post by Eelke »

@Acyd Burn: one remaining question: is there some mechanism that will set the user_lastmark automatically, to a certain limit, to avoid the tables filling up when a user never manually clicks the mark all read link?
.Johnny
Registered User
Posts: 7
Joined: Wed May 23, 2007 8:28 am

Re: Marking of topics/forums logic (technical)

Post by .Johnny »

I agree; that would be useful. the drawback of the new mechanism is that after a while all forums will contain unread posts (rendering the indication useless). There should be a method to apply the concept of users not being interested in certain topics. They don't read them, so that could be a good indicator after a while. I'm curious.
User avatar
Eelke
Registered User
Posts: 2903
Joined: Thu Dec 20, 2001 8:00 am
Location: NL, Bussum
Name: Eelke Blok
Contact:

Re: Marking of topics/forums logic (technical)

Post by Eelke »

That's not what I meant. I only meant there is probably some safeguard to stop the topics mark table to fill up with all the various topics a user has read in their lifetime on the boards (in case they never click any "mark topics read" links). It would probably involve setting the user mark time to some specific moment in the past and stripping out all individual forum and topic mark times that are older from their respective tables.

Edit: from the 2.0.x and general chat forums (which I rarely, if ever, read), my guess would be that it is half a year? The topics I have not read span to the middle of november 2006, for me.
.Johnny
Registered User
Posts: 7
Joined: Wed May 23, 2007 8:28 am

Re: Marking of topics/forums logic (technical)

Post by .Johnny »

I think I mean sortof the same thing, but it doesn't really matter. I am guessing the user_lastmark time was set when the board was upgraded, at least it did exactly that on my board.

Based on acydburns comments, here's a query that will effectively retrieve all unread topic_id's for user with user_id=4; ofcourse you would still need to distill topic permissions.

Code: Select all

SELECT * FROM (
  SELECT t.topic_id, t.topic_last_post_time tlpt ,tt.mark_time as tmt, ft.mark_time as fmt, u.user_lastmark as umt
  FROM phpbb3_users u, phpbb3_topics t
  LEFT JOIN phpbb3_topics_track tt
    ON tt.topic_id = t.topic_id AND tt.user_id=4
  LEFT JOIN phpbb3_forums_track ft
    ON ft.forum_id=t.forum_id AND ft.user_id=4
  WHERE u.user_id=4 AND topic_last_post_time > u.user_lastmark
) marktimes
WHERE 1 AND NOT ((tlpt <= tmt AND NOT ISNULL(tmt)) OR (tlpt <= fmt AND NOT ISNULL(fmt)))
it's difficult to guess how expensive this query will be overtime. For now it is quitte cheap, but thats only because the user_lastmark time is so high.
Post Reply

Return to “phpBB Discussion”