Bulk Suppressing Topics from /latest Not Working as Expected

AI-generated summary

The discussion is about an issue with the Discourse Suppress Category from Latest plugin, where bulk suppressing topics from the /latest page is not working as expected. huynhthai824 attempted to use a Rails console command to hide topics from about 200 categories, but the topics were still visible on the homepage.

RGJ, the plugin author, identified the issue and provided a solution. The correct custom field key should be :suppress_category_from_latest instead of suppress_latest. Additionally, the category needs to be saved using save! to clear the cached values.

The corrected command is:

Category.all.each do |cat|
  cat.custom_fields[:suppress_category_from_latest] = true
  cat.save_custom_fields(true)
  cat.save!
end

huynhthai824 confirmed that this solution worked, and the categories are now successfully suppressed from the /latest page.

Hi everyone,

I’m currently using the Suppress category from latest plugin to hide topics from the /latest page while still displaying them within their respective categories. I have about 200 categories that I want to hide from /latest, and only around 10 categories that should show topics on the homepage.

To accomplish this, I attempted to run the following code in the Rails console:

Category.all.each do |cat|
  cat.custom_fields["suppress_latest"] = true
  cat.save_custom_fields(true)
end

The command seems to execute without errors (it even returns {"suppress_latest"=>"t"}), but when I check the /latest page, the topics from those categories are still visible.

Here are the steps I’ve already taken:

  • I ran ./launcher rebuild app and ./launcher restart app
  • I confirmed via Rails console that the custom field is set to "t" for the affected categories
  • I’ve also tried clearing caches, but nothing seems to change

It appears that even after setting the custom field, the topics from these categories still show on the homepage. Has anyone experienced this issue or found a way to bulk suppress topics from /latest effectively? Is there a known compatibility issue with subcategories, or should the plugin be using a different key/value for suppression?

Any guidance or alternative approaches would be greatly appreciated!

Thank you!

A quick look at core doesn’t find suppress_latest in the code.

Maybe you want the Mute all categories by default site setting?

Plugin author here!

Should be

cat.custom_fields[:suppress_category_from_latest] = true

But… these values are also cached in a class variable. The easiest way to deal with this is to save! the category as well (see here)

So this works

Category.all.each do |cat|
  cat.custom_fields[:suppress_category_from_latest] = true
  cat.save_custom_fields(true)
  cat.save!
end

Hi RGJ,

Thank you so much for your guidance. I ran the following command in my Rails console:

Category.all.each do |cat|
  cat.custom_fields[:suppress_category_from_latest] = true
  cat.save_custom_fields(true)
  cat.save!
end

Everything worked perfectly! My categories are now successfully suppressed from the /latest page. I really appreciate your help.

Best regards,