Plugin - Get unseen topic count per tag

AI 生成的摘要

The discussion revolves around implementing a plugin to display the unseen topic count per tag. jack2 proposes observing topicTrackingState.messageCount and fetching unseen topics via the API to determine their tags, but sam warns this approach is expensive. sam suggests publishing tag-related data in core, though it would add performance overhead. jack2 considers using topicTrackingState.state to get unseen topic IDs and then retrieve their tags, but sam again cautions against this due to high cost. jack2 notes that the current limitation means new topics on a tag page don’t trigger the ‘new topic’ notification, highlighting a UX issue.

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)

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.

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

That is SUPER expensive, would recommend against it

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

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), any new topic with that tag won’t trigger the “1 new or updated topic. Click to show” message.