How I debugged and fixed issues with unread/new counts

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 :dagger:

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

  1. When a topic was deleted we were not notifying the topic tracking state about this happening

  2. 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.

Sam, when a user A creates a topic and stays on it.
User B comes and moves the new topic to another category.
Should the topic refresh the category automatically? It isnโ€™t happening.

Yeah this should refresh category on category edit.

Most of my users create the topic on the wrong category, so I edit then all day. Sometimes they need a ninja edit and since the topic is still on the wrong category because the change hasnโ€™t been received, when they edit the text the topic goes back to the original category.

Which I edit again, and we have now 4 revisions.

Sure, open a bug report on it (but search first cause one may exist)