Ability to delete tags with < N topics

I just stumbled across this wonderful feature, “delete unused tags”. And it left me wanting more!

Continuing the discussion from A comprehensive guide to Discourse tags:

We have many tags with “count: 1” as tag creation is not at all locked down and some folks just treat them as hash tags. I still believe in keeping permissions open for tags, but it’d be nice to be able to periodically weed the garden more easily.

I’d love to find ways to nudge people to consider tags as a means to “grouping” related topics and to only create tags when they think (or know!) that they will be used more than once.

But in the mean time, I think extending the existing feature to allow for “deleting tags used by less than __ topics” could be a nice improvement that we would use.


Even fancier, I could imagine a setting that would automatically sweep tags and delete tags based on the following criteria:

count < N && topic_last_updated > X months ago

Basically, you let tags have a chance to get a toe hold. Their life is renewed if new topics are posted before some timeout. But if no new topics have been posted for more than, say 3 months, and the tag has less than 5 topics, then just get rid of it.


I also think these are good suggestions for improving the tag cleanup function @neil


I’ve never seen this button either, and I agree that an auto-cleanup feature would be useful. It should also be careful about not deleting tags that are staff-only. There are probably other cases where some tags shouldn’t be deleted automatically.


In the meantime, here’s a #plugin:data-explorer query that can help folks identify candidate tags for deletion:

-- [params]
-- int :months_since_used = 24
-- int :max_topic_count = 50

t as (
    current_date::timestamp - (:months_since_used * (INTERVAL '1 months')) as cutoff_date
topic_tag_dates as (
  select tags.id, tags.name, tags.topic_count, topics.last_posted_at as last_used
  from topic_tags
  left join tags
  on topic_tags.tag_id = tags.id
  left join topics
  on topic_tags.topic_id = topics.id
max_last_used as(
  select id, max(last_used) mx from topic_tag_dates
  group by id
tag_last_used as (
  select topic_tag_dates.id, name, topic_count, last_used from topic_tag_dates
  left join max_last_used
  on topic_tag_dates.id = max_last_used.id
  where max_last_used.mx = topic_tag_dates.last_used
select id,name,topic_count,last_used from tag_last_used, t
  where tag_last_used.last_used < t.cutoff_date
  and topic_count < :max_topic_count
  order by topic_count desc

I apologise for the bump,

Yes - this is heavily needed as some people on my forum decided it would be funny to joke around and post let’s say ‘interesting’ tags not appropriate for all ages therefore I’d like to see this sort of feature.


1 Like