¿La forma más segura de eliminar en masa etiquetas con un prefijo dado en la consola de Rails?

Hi all,

I’ve been experimenting with importing events via ICS into Discourse. As part of that, a lot of tags were created automatically, all starting with the prefix ics-. I’d now like to remove them in bulk.

From Rails console I can list them like this:

Tag.where("name LIKE ?", "ics-%").pluck(:name)

And I’ve tried deletion with:

Tag.where("name LIKE ?", "ics-%").destroy_all

That seems to work, but I’m not sure if this is the best / safest way in a Discourse context:

  • Will callbacks handle cleaning up topic_tags and counts correctly?
  • Should I be using destroy_all (safe but slower) vs. delete_all (faster but maybe leaves dangling rows)?
  • Do I need to rebuild tag counts afterwards?
  • Is there any admin-facing UI or rake task I should prefer over Rails console?

What’s the recommended approach for bulk-removing tags with a given prefix while keeping the database consistent?

Thanks in advance!