I’ve been hit by this issue when using the API. In my plugin, I need an exact topic count, so I’m forced to load each tag in order to count the visible topics. It seems to work right now, but it’s a waste of bandwidth and I’m afraid one day I will hit a Discourse rate limit for API calls.
Ok, I’m re-doing my response as I’m pretty sure I figured out everything that’s going on here
As @ninjapenguin mentions, if you have a tag and delete all of the topics that have that tag applied, the tag remains listed on the tags page and the count unchanged. I believe this is happening because the topics still technically exist and they continue to hold the tag.
@syl if you navigate to the tete tag’s topic list as shown in your screenshot and then add
?status=deleted
to the end of the URL, you should see two deleted topics listed with the tete tag.
The information message in your second screenshot corresponds to the the number of deleted topics that have the tag applied.
I feel like we probably shouldn’t factor in deleted topics when counting/listing tags, but this may not be a super trivial change given how everything is stored in the database. What do you think @codinghorror?
In a standard forum, I think deleted topics explain most discrepancies between the topic count displayed in the tag list and the actual number of topics a user can see within each tag. Fixing this would already be a big plus. But notice that discrepancies also occur when a non-admin user is looking at a tag containing private topics.
This I cannot reproduce. If I have a tag that has only been used on a PM or a topic in a restricted category, a user without access to those topics does not see the tag included in the tag list.
The only unfortunate behavior I’m seeing at the moment is what I mentioned surrounding deleted topics.
I took a look at the code and have noticed a few things.
There are two columns in the tags table that can influence the tag count: topic_count and pm_topic_count. These counts are incremented/decremented on tag application/removal. Non-admin users only ever see the value of topic_count.
There is nothing to adjust the count on the fly based on a user’s individual topic access.
Based on what I’m seeing, we don’t have a bug, just a limitation based on the current implementation. I think everything that has been talked about here falls under the “feature request” banner and can be summarized as:
Make tag counts on the tags page dynamic so that they reflect what a user will actually see when they navigate to the tag’s topic list.
Thanks a lot @tshenry. That sounds very good, and might explain why a got the issue a lot more on my dev instance (maybe it doesn’t run the consistency job). I will check this.
P.S.: right now, the documentation tag here on Meta has a count of 5 but only 4 topics that I can see. I will check again in 12 hours