Today I fixed a couple of issues with incorrect new and unread counts.
https://github.com/discourse/discourse/commit/fbdd9c00345f7df31fb194633923e242f037bbbf
The fixes themselves though interesting are less interesting than the debugging method I used to track it down.
This is how I diagnosed the issues
Run multiple browser windows and catch one misbehaving
Once I isolated a bad actor
Open chrome dev tools and run:
Discourse.__container__.lookup('topic-tracking-state:main')
Then walk through the states
array:
Using this information I was able to discover that
-
When a topic was deleted we were not notifying the topic tracking state about this happening
-
When we were reporting “unread” “latest” etc we were not informing topic tracking state if the topic at hand was a PM, causing PMs to corrupt the counts
There may be more edge cases here, but that is the general gist of how I debug it.
MessageBus is working like a champion and never dropping messages or corrupting ordering.