# Plugin - Get unseen topic count per tag

**URL:** https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937
**Category:** Development
**Created:** [2017年九月28日 12:39 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937 "2017-09-28T12:39:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年九月28日 12:39 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937/1 "2017-09-28T12:39:51Z")

</div>

In my plugin, I would like to display the **unseen** topic count for each tag.

I plan to implement this feature like this:

1. Observe the `topicTrackingState.messageCount` property.
2. Each time there’s a change, use the API to fetch all topics of all tags and check the `unseen` field.

This seems heavy. Is there another way?

(notice that, for simply getting the topic count per tag, there’s a simpler way: the `tags.json` API returns a list of tags with a `count` field)

---

<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: [2017年九月29日 02:40 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937/2 "2017-09-29T02:40:43Z")

</div>

We publish category now with the “new information” I am not against adding publishing of tags as well in core.

The tricky thing though is that this adds an extra join each time we publish info. Additionally, when we generate the initial cache we do not include tags, adding them will be expensive.

This is going to be painful.

---

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年九月29日 10:28 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937/3 "2017-09-29T10:28:26Z")

</div>

Thanks @sam.

I’ve just seen that I can get the unseen topic ids from the `topicTrackingState.state` object (as you mentioned, I can see the category in there, but not the tags). So here is a better plan:

1. Observe the `topicTrackingState.messageCount` property.
2. Each time there’s a change, use the API to load the unseen topics and get their tags

---

<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: [2017年九月29日 10:30 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937/4 "2017-09-29T10:30:44Z")

</div>

That is SUPER expensive, would recommend against it

It is a very hard problem, I would just make the plugin publish extra messages.

---

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年九月29日 12:13 UTC](https://meta.discourse.org/t/plugin-get-unseen-topic-count-per-tag/70937/5 "2017-09-29T12:13:13Z")

</div>

Thanks, I will think about it.

Tell me if I’m wrong, but a consequence of this tag limitation is that, when you’re on a tag page (example [here](https://meta.discourse.org/tags/pr-welcome)), any new topic with that tag won’t trigger the “1 new or updated topic. Click to show” message.
