Moving from sub-categories to tags?

Is there a limit to the number of tags a category/community can have?

2 Likes

Topics or tags? In both cases you shouldn’t ever hit a limit.

4 Likes

I mean tags.
I’m working on a forum design that eliminates sub categories (because we were reaching thousands and it was getting really slow in searches and subscribing to specific categories), and moves all those to tags. Tags will be restricted to categories, but the total number of them will be over a 1000, and eventually even more. Is that expected to have better performance over sub-categories?

Also, can I subscribe to new topics/posts on a tag?

1 Like

Yes absolutely. Tags are extremely light-weight compared to categories/sub-categories.

You can! At the end of the guide is a link to How do I set tag tracking level defaults historically where you can set default watched tags for all of your users. These can also be adjusted by individual users when they view a tag’s topic list, or through their user preferences (/my/preferences/tags).

6 Likes

Thanks for your responses. Really helpful!
One more thing I want clarity on:

Can I use the admin API to create a new tag? I don’t see that option in the tags API, it only allows me to create/update new tag groups.

My second thought was to create a new topic and add my desired tags to it through the API, but the available options in the docs don’t have a tags field in them.

Here are my options:

Why I need this:
I’m trying to test how my system will perform if I have 5000 tags.
I’ll also eventually need this if I migrate my topics from subcategories to tags. I will need to create those tags first.

2 Likes

When trying to send a request to create a tag group with new tag names I’m trying this

# Python
 payload = {
    'api_key': constants.DISCOURSE_RAILS_API_KEY,
    'api_username': constants.DISCOURSE_RAILS_API_USERNAME,
    'name': 'new-tag-group',
    'tag_names': ['new_tag1', 'new_tag2']
}

This successfully creates the new tag group but the response doesn’t have the tags in the tag_names array:

'_content': '{"tag_group":{"id":6,"name":"new-tag-group","tag_names":[]"}'

However, when I try to do this through the admin panel and look at the network call, it sends them similarly:

Am I doing something wrong in the request?

1 Like

Tags are created upon first application, so you will need to create at least one topic with the new tag for it to be available. I believe this is a case where the API documentation doesn’t have every possible option included. If you are planning to work with the API, I would recommend checking out How to reverse engineer the Discourse API

If you create a topic with a new tag through the UI and look at the XHR in your browser’s dev tools, you should see something like this (note the array of tags):

Once you have the tag created, you should be able to use a method like Bulk Tag All Topics Within a Category and then Move all topics from one category to another to achieve what you are looking for.

Remember to take a backup first before running rake tasks like those :slight_smile:

5 Likes

Thanks for the help Taylor! Luckily I had figured it just like that after my last comment.
I used the create tag group API to achieve this.
The problem is that (like in the photo) the json key expected is tag_names[] and not tag_names,

However, in the API docs at Discourse API Docs, it does say tag_names. Should that be updated for clarity?

3 Likes

No problem! Glad you were able to get it figured out. Since this all might be useful to someone in the future, I’ve gone ahead and moved it to a new topic (it would have been auto-deleted if it remained on the howto topic.)

It sure sounds like it. @blake might be able to weigh in when he gets a chance.

5 Likes

Yep! It probably needs updating. I’ve added it to my list.

6 Likes

Hey Taylor, another call for guidance:

I see these links about bulk operations, however, I’m unsure how to administer them in the production environment.
I wouldn’t have access to the instance running and hosting discourse, but I need to write scripts, test them on a staging instance, and then deliver them to production so they can be run.
How is this achieved? I am seeing topics about db:migrate, etc, but it is unclear.
Could you point me in the right direction?

Here are the steps I want to take:

  1. Create a new category.
  2. Tag all topics in existing categories with a tag named the same as the category name.
  3. Move all topics to the new category.
  4. Delete all old categories.
  5. Create tag groups from these newly formed tags.
  6. Restrict these tag groups to the new category.
  7. Edit some category settings to this new category.

I’ve figured out how to do this all through the API. Already written the code for it, too.
I’m just wondering if it’d be more efficient to do this with migrations?

2 Likes

Hmm, you would need to have console access in order to run any of the bulk operations scripts/tasks. On our hosting we are happy to run one-off bulk operation scripts/task for customers, so I would reach out to your hosting provider and see if they can take care of it for you.

In my mind, this is how I would handle your steps:

  1. Easy enough to do from the UI
  2. Bulk Tag All Topics Within a Category
  3. Move all topics from one category to another
  4. Either through the UI or rake destroy:categories[10,11,12,18,30]
  5. Probably easiest through the UI
  6. UI
  7. UI

There shouldn’t be any need to do anything with db:migrate. If you can have your hosting provider run the necessary bulk operations tasks for you, then that would be more efficient than using the API.

I would check on whether your hosting provider will run the task first then decide what to do from there.

3 Likes

Thanks for the quick response.

So yes, there are people in the team who do have access to the prod hosting environment.
Could you point me in the right direction to learn how to write these rake scripts, and how to run them?

All of the information you need should be included with the links I posted above :slight_smile: They are already written, you just need to supply the parameters which should be explained in the relevant sections of the Administrative Bulk Operations topic. Check the top of the topic for initial instructions.

2 Likes