# How I debugged and fixed issues with unread/new counts

**URL:** https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738
**Category:** Development
**Created:** [3월 30, 2016, 12:42오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738 "2016-03-30T00:42:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 30, 2016, 12:42오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738/1 "2016-03-30T00:42:10Z")

</div>

Today I fixed a couple of issues with incorrect new and unread counts.

[https://github.com/discourse/discourse/commit/fbdd9c00345f7df31fb194633923e242f037bbbf](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

 ![](https://global.discourse-cdn.com/meta/original/3X/4/8/48036bd6e9d79ff62f90cc72847f7a241060530a.png)

Once I isolated a bad actor 🗡

Open chrome dev tools and run:

```plaintext
Discourse. __container__.lookup('topic-tracking-state:main')

```

Then walk through the `states` array:

 ![](https://global.discourse-cdn.com/meta/original/3X/6/4/640f618402bbb273daed4bbf2273c85b71ceffe4.png)

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.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [3월 30, 2016, 2:55오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738/2 "2016-03-30T02:55:56Z")

</div>

> [@sam](#):
>
> When a topic was deleted we were not notifying the topic tracking state about this happening

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 30, 2016, 3:07오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738/3 "2016-03-30T03:07:52Z")

</div>

Yeah this should refresh category on category edit.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [3월 30, 2016, 3:10오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738/4 "2016-03-30T03:10:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 30, 2016, 3:11오전 UTC](https://meta.discourse.org/t/how-i-debugged-and-fixed-issues-with-unread-new-counts/41738/5 "2016-03-30T03:11:42Z")

</div>

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