Notification counts are inconsistent and wrong

I am running a week-old very small forum, just updated to the current version, and I am still seeing this very strange behavior. The notification counts (New, etc) do not appear to correspond to any real counts, and change at random.

Currently I see “New (3)”

Clicking on “New” I see no new posts, and the “(3)” is gone.

Clicking back to the home page I no longer see “New (3)” in the menu.

If I reload the page, “New (3)” comes back.

Clicking on “Latest” I see “Unread (2)”, however none of the messages in the list have an unread indicator.

Clicking on “Unread (2)” shows me there are no unread messages.

Sometimes when I click “New”, I see no new messages and an “Unread (1)” indicator

I’ve checked /sidekiq/ and everything looks fine, there are no queued or backed up jobs.

3 Likes

Can you confirm what version of Discourse your site is on? It should be shown near the top of your site’s admin dashboard.

3 Likes

2.5.0.beta4

( 74db317974 )

2 Likes

Do you have any muted tags or categories.

Do you have a consistent repro?

2 Likes

Nothing muted, and this has continued to happen even with new activity in the forum. Feel free to make an account if you’d like to see it first-hand. (I haven’t actually confirmed if other people see this or if it’s unique to my account.)

Look in your admin section are there any warnings, is sidekiq running ?

1 Like

No warnings, sidekiq looks fine. Assuming I’m reading this right.

Are you running cloudflare or a similar CDN. I’ve noticed some notification latency with cloudflare, even with the acceleration turned off. Rocket loader for example.

1 Like

Oh I missed this… so something is consistently wrong. This means the server is telling the client there are a bunch of new topics, but then when you drill in they are missing.

I have seen this happen before with scheduled posts … do you use them? Debugging this is a bit tricky, we need to get the list of topic_ids the client thinks are new

If this is happening now run:

SELECT 
           u.id AS user_id,
           topics.id AS topic_id,
           topics.created_at,
           highest_staff_post_number highest_post_number,
           last_read_post_number,
           c.id AS category_id,
           tu.notification_level
FROM topics
JOIN users u on u.id = 1
JOIN user_stats AS us ON us.user_id = u.id
JOIN user_options AS uo ON uo.user_id = u.id
JOIN categories c ON c.id = topics.category_id
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = 1
WHERE u.id = 1 AND
      
      topics.archetype <> 'private_message' AND
      ((1=0) OR ("topics"."deleted_at" IS NULL AND topics.created_at >= GREATEST(CASE
                  WHEN COALESCE(uo.new_topic_duration_minutes, 2880) = -1 THEN u.created_at
                  WHEN COALESCE(uo.new_topic_duration_minutes, 2880) = -2 THEN COALESCE(u.previous_visit_at,u.created_at)
                  ELSE ('2020-05-13 00:36:29.100619'::timestamp - INTERVAL '1 MINUTE' * COALESCE(uo.new_topic_duration_minutes, 2880))
               END, us.new_since, '2020-05-07 14:46:17') AND tu.last_read_post_number IS NULL AND COALESCE(tu.notification_level, 2) >= 2 AND topics.created_at > '2020-05-07 14:46:17' AND (category_users.last_seen_at IS NULL OR topics.created_at > category_users.last_seen_at))) AND
      
      
      topics.deleted_at IS NULL AND
      
      NOT (
        last_read_post_number IS NULL AND
        COALESCE(category_users.notification_level, 1) = 0
      )

UNION ALL

SELECT 
           u.id AS user_id,
           topics.id AS topic_id,
           topics.created_at,
           highest_staff_post_number highest_post_number,
           last_read_post_number,
           c.id AS category_id,
           tu.notification_level
FROM topics
JOIN users u on u.id = 1
JOIN user_stats AS us ON us.user_id = u.id
JOIN user_options AS uo ON uo.user_id = u.id
JOIN categories c ON c.id = topics.category_id
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = 1
WHERE u.id = 1 AND
       topics.updated_at >= us.first_unread_at AND 
      topics.archetype <> 'private_message' AND
      (("topics"."deleted_at" IS NULL AND tu.last_read_post_number < topics.highest_staff_post_number AND COALESCE(tu.notification_level, 1) >= 2) OR (1=0)) AND
      
      
      topics.deleted_at IS NULL AND
      
      NOT (
        last_read_post_number IS NULL AND
        COALESCE(category_users.notification_level, 1) = 0
      )

replacing user_id = 1 with your user id (you can find it by running select id, username from users where username = 'yourusername')

If this is happening can you install data explorer and see what is going on.

1 Like

No CDN, no scheduled posts, this is just a stock Discourse install in Docker on a Linode VPS, nothing fancy at all.

I just installed the data explorer plugin and now I can’t even get the settings page to load. It crashes with a JS error in the console:

workbox-strategies.prod.js:1 Uncaught (in promise) no-response: no-response :: [{"url":"https://forum.livevideotech.today/admin/site_settings"}]
    at a.makeRequest (https://forum.livevideotech.today/javascripts/workbox/workbox-strategies.prod.js:1:2145)
1 Like

Any custom plugins? Are you on the beta branch or tests-passed? If you are on beta can you change to tests-passed for now.

One plugin: https://github.com/discourse/discourse-solved

I’m on 2.5.0.beta4, which I ended up at after a stock install process and running the prompted upgrades.

I don’t know how to switch to a specific branch, also that sounds risky given that one of the only search results when trying to find out how was someone who had some failed database migrations trying to do that.

I connected to the database on the command line and ran the query, and there were no results:

discourse(#         last_read_post_number IS NULL AND
discourse(#         COALESCE(category_users.notification_level, 1) = 0
discourse(#       );
 user_id | topic_id | created_at | highest_post_number | last_read_post_number | category_id | notification_level
---------+----------+------------+---------------------+-----------------------+-------------+--------------------
(0 rows)

discourse=#

To clarify, right now in the current state, when I load the home page I see “New (1)”, clicking on “New (1)” I do not see any new posts. Clicking back to the home page the “New (1)” goes away. Reloading the page makes it show up again.

You are running an old commit and are not on beta

Can you rebuild from the console. Data explorer should work

It says I’m on 4078b22887 which is exactly one commit behind master.

Oh right, sorry, can you confirm data explorer is still broken after you enable it on site settings? Also can you try in a different browser (Firefox/chrome) does the work box error persist?

I’m going to deal with the data explorer issue later, I don’t want to keep rebuilding the forum taking it down every time. I’ll just run the queries on the command line.

Current status: “New (4)”

 user_id | topic_id |         created_at         | highest_post_number | last_read_post_number | category_id | notification_level
---------+----------+----------------------------+---------------------+-----------------------+-------------+--------------------
       1 |      116 | 2020-05-13 06:48:33.784078 |                   1 |                       |           5 |
       1 |      118 | 2020-05-13 07:29:47.423296 |                   1 |                       |           5 |
       1 |      117 | 2020-05-13 06:52:39.448473 |                   1 |                       |          13 |
       1 |       31 | 2020-05-03 14:13:53.109324 |                   4 |                     3 |           7 |                  2

Clicking on “New (4)” I see three posts, 118, 117, 116. That topic_id 31 doesn’t appear.

Clicking back to the home page then shows “New (3)”

Query results still return the same 4.

4 Likes

Ok this is interesting, can you navigate to topic 31, is there something odd about it? That is a unread topic (last_read_post_number is 3) … the query indicates we think you have 3 new and 1 unread.

I keep thinking maybe something is going on client side for you with web worker caching.

Are you on Chrome or Firefox … can you try the other one… can you try your browser in incognito with no extensions?

4 Likes

Oh @martin and I just uncovered a bug … By chance are you muting any tags?

There is a bug where counts go off if you have muted tags and ANY topics that are 100% untagged, they end up missing from unread.

3 Likes

I am not 100% sure this exactly your issue @aaronpk … but this fix is now in:

https://github.com/discourse/discourse/commit/2acec4370bc8b7bbecf297237c590b1f9d8a8f81

6 Likes