Unread Topic Bug

in Userscripts.org discussion
Subscribe to Unread Topic Bug 25 posts, 7 voices



dob Scriptwright

Here is the process:
I've got no unread topics, then I open up a new thread, and next time I visit /forums/, it'll show the green icon instead of the gray one. Obviously, I've read my own topic, so it's not really unread.
Same thing happens when I click on a reply directly (be it the one shown to the right, or the "last" link). In both cases, I've seen the topic before, but it still shows up as "unread".

 
ScroogeMcPump Scriptwright

I'm not seeing any green icons, despite not being here for a week. (Luckily, I remember my last visit, so I can sort out the new posts manually - this time.)

 
jerone Scriptwright

No problems here, but I love an "Mark all topics read"-button.

 
Aquilax Scriptwright

It's happens to me when I reply to a topic, it appears anyway green, I have to read it again to turn it gray.

 
dob Scriptwright

>> Aquilax

Yes, that's the bug I mean.
I don't see why I should "Mark all topics read", it kind of defeats the purpose.

 
Jesse Andrews Admin

I've noticed weird things in the past as well.

I inherited this code from "beast" (rails based forum software). I've not really dug into it. So I'm not really sure what it is doing internally to track when a post is marked as read or not.

I'll check into it tonight.

 
dob Scriptwright

It seems to me like there are no green icons anymore at all...

/edit: just after I've written that, it seems to be fixed.
Hmm.

/edit: Now it's all back to gray. I have not looked at all threads...

 
ScroogeMcPump Scriptwright

I'm using a saved session that opens pages for all of the topic lists at the same time. This time, one list had green icons, and the others didn't. Weird.

 
ScroogeMcPump Scriptwright

I'm not really sure what it is doing internally
An educated guess: It's storing only one "last visited" value, rather than one per forum, i.e., if it's been 24 hours since my last visit, when I go to /forums/1 it correctly flags posts from the last 24 hours, but if I were to go to /forums/2 five minutes later, it'd only flag posts from the 5 minutes since I hit /forums/1. This is why I see only one forum flagged properly; I use a bookmark that opens all the forums in separate tabs simultaneously, and the one marked properly is whichever request hits the server first.

 
w35l3y Scriptwright

i think i got it
if you open an unread topic while another one is still running, then the first topic will remain green (or "unread")

 
Jesse Andrews Admin

I'm sure there are bugs here since I've never touched this code:

Whenever you view a topic, it modifies your session by storing the last time the topic.id was viewed.

(session[:topics] ||= {})[@topic.id] = Time.now.utc if logged_in?

The session is stored in a cookie (signed so it cannot be tamper with), so there could be issues with tabs (although I think rails is designed so it won't be)

Then when a list of topics is rendered if the following is true then the topic has "new activity" and is marked in green.

topic.replied_at > (session[:topics][topic.id] || last_active)

Whenever a topic is updated the replied_at is updated.

last_active is defined as:

session[:last_active] ||= Time.now.utc

I hadn't read the code before and nothing seems to stick out... Then again I'm exhausted :(

 
Jesse Andrews Admin

If you aren't used to ruby ||= is only define this if it isn't already.

c = 3
c ||= 1

Would leave c equal to 3, but if c was nil/null/false/... then it would become 1.

 
Jesse Andrews Admin

To help figure this out, if you append a query param of debug=1 to the end of any URL it will output some of the session information: last_active and topics

 
jerone Scriptwright

Damn I wish I knew some Ruby, or had spare time to learn it.

 
JoeSimmons Scriptwright

Yeah if I reply to a topic, then go back to the forum it was posted in, it's green until I read it again.

 
ScroogeMcPump Scriptwright

append a query param of debug=1
Okay, I made a new bookmark using that; I'll let you know what happens when I use it next time (gotta have some new messages).

 
w35l3y Scriptwright

clicking as fast as possible...

http://userscripts.org/topics/18269?debug=1 (kept unread)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {18240=>Tue Nov 25 12:52:22 UTC 2008, 18224=>Tue Nov 25 12:36:37 UTC 2008, 18269=>Tue Nov 25 18:56:11 UTC 2008}

http://userscripts.org/topics/18240?debug=1 (kept unread)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {18240=>Tue Nov 25 18:56:12 UTC 2008, 18224=>Tue Nov 25 12:36:37 UTC 2008}

http://userscripts.org/topics/18224?debug=1 (changed to read)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {18240=>Tue Nov 25 12:52:22 UTC 2008, 18224=>Tue Nov 25 18:56:13 UTC 2008}

===============================================================================

waiting the topic to load...

http://userscripts.org/topics/18262?debug=1 (changed to read)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {9505=>Tue Nov 25 12:58:21 UTC 2008, 18262=>Tue Nov 25 19:08:11 UTC 2008, 18171=>Tue Nov 25 12:58:19 UTC 2008}

http://userscripts.org/topics/18171?debug=1 (changed to read)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {9505=>Tue Nov 25 12:58:21 UTC 2008, 18262=>Tue Nov 25 19:08:11 UTC 2008, 18171=>Tue Nov 25 19:08:22 UTC 2008}

http://userscripts.org/topics/9505?debug=1 (changed to read)

    * last_active: Mon, 24 Nov 2008 23:15:42 CST -06:00
    * topics: {9505=>Tue Nov 25 19:08:29 UTC 2008, 18262=>Tue Nov 25 19:08:11 UTC 2008, 18171=>Tue Nov 25 19:08:22 UTC 2008}

 
Jesse Andrews Admin

one obvious bug now that I've gotten some sleep is that when you post a reply on a topic it should set your last seen time for the topic to the time of your reply

 
ScroogeMcPump Scriptwright

Okay,
/forums/1?debug=1 shows zero green icons and

  • last_active: Tue, 25 Nov 2008 20:58:50 CST -06:00
  • topics: {1=>Wed Nov 26 04:14:12 UTC 2008}
, despite there being new messages on three different topics since I last viewed the page in question, about 12 hours ago.

/forums/2?debug=1 shows zero green icons and

  • last_active: Tue, 25 Nov 2008 22:14:12 CST -06:00
  • topics: {2=>Wed Nov 26 04:14:12 UTC 2008}
, despite there being new messages on two different topics.

/forums/3?debug=1 shows zero green icons and

  • last_active: Tue, 25 Nov 2008 22:14:12 CST -06:00
  • topics: {3=>Wed Nov 26 04:14:12 UTC 2008}
, despite there being new messages on three different topics.

I suspect I'm misinterpreting how this is supposed to work, but it strikes me as wrong that my access of /forums/1 at 22:14:12 CST should be affecting last_active for /forums/2 and /forums/3, and also wrong that last_active for /forums/1 should reflect activity at 20:58:50 CST that had nothing to do with any of the forums.

 
Jesse Andrews Admin

session[:last_active] ||= Time.now.utc

should mean that last_active is only changed when it isn't already set. I don't see anything else that modifies it. I think that it only gets set the first time you visit.

Long day - will dive into this more tomorrow.

 
Aquilax Scriptwright

I have also a new bug, now when I'm on the main page of the forums (http://userscripts.org/forums) and I open one forum in another tab and reload the main page, the forum is marked as "read" even if I haven't still read any topic.

Main page before opening a forum in a new tab:
Forum session information:

* last_active: Tue, 25 Nov 2008 19:43:26 CST -06:00
* topics: {3=>Wed Nov 26 13:18:58 UTC 2008}

Main page reloaded after just opening a forum in a new tab:
Forum session information:

* last_active: Tue, 25 Nov 2008 19:43:26 CST -06:00
* topics: {9505=>Wed Nov 26 13:20:44 UTC 2008, 3=>Wed Nov 26 13:18:58 UTC 2008}

Main page reloaded after just opening a second forum in a new tab:
Forum session information:

* last_active: Tue, 25 Nov 2008 19:43:26 CST -06:00
* topics: {9505=>Wed Nov 26 13:20:44 UTC 2008, 2=>Wed Nov 26 13:27:33 UTC 2008, 3=>Wed Nov 26 13:27:21 UTC 2008}

Main page reloaded after just opening a third forum in a new tab:
Forum session information:

* last_active: Tue, 25 Nov 2008 19:43:26 CST -06:00
* topics: {9505=>Wed Nov 26 13:20:44 UTC 2008, 1=>Wed Nov 26 13:28:20 UTC 2008, 2=>Wed Nov 26 13:27:33 UTC 2008, 3=>Wed Nov 26 13:27:21 UTC 2008}

 
ScroogeMcPump Scriptwright

With todays foray into the forums:

/forums/1?debug=1 shows six green icons and

  • last_active: Tue, 25 Nov 2008 22:56:57 CST -06:00
  • topics: {1=>Wed Nov 26 17:33:04 UTC 2008}
, which is actually the correct result (for a change).

/forums/2?debug=1 shows zero green icons and

  • last_active: Wed, 26 Nov 2008 11:33:04 CST -06:00
  • topics: {2=>Wed Nov 26 17:33:05 UTC 2008}
, despite there being new messages on four different topics.

/forums/3?debug=1 shows zero green icons and

  • last_active: Wed, 26 Nov 2008 11:33:05 CST -06:00
  • topics: {3=>Wed Nov 26 17:33:06 UTC 2008}
, despite there being new messages on three different topics.

And I didn't notice this until now, but if session[:last_active] means that only a single "last active" value is being saved for the entire session, then that's your problem right there. Next time I visit /forums/4 (which I only do about once a week - bananas make me constipated :-)), I don't want it to show the status since the last time I requested a us.o page; I expect it to reflect the status since I last visited that page - /forums/4 - specifically.

 
Jesse Andrews Admin

this code is horrible - it just gets worse: the session[:forums] and session[:topics] share the same values (eg, it is 1 hash instead of 2 distinct hashes).

That is why @ScroogeMcPump was getting that Topics 1,2,3 were set when he visited a forum!

This code HAS to be rewritten - and stored the view time in the database...

 
jerone Scriptwright

I think good catch, but also a lot off work.

 
Jesse Andrews Admin

I was looking at what phpBB did - and it seems to not create any database indexes! That's crazy.

The basic idea is pretty simple - perhaps I'll implement it and do a few EXPLAINs to see if the indexes (on both topic_id, user_id) is the right idea or if it is naive since I've never implemented this.

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel