A platform for community discussion. Free, open, simple.
FEATURE: Add rake task to mark old hashtag format for rebake (#19876)
Martin Brennan56a93f7532ff
diff --git a/lib/tasks/hashtags.rake b/lib/tasks/hashtags.rakenew file mode 100644index 00000000000..9810e653b78--- /dev/null+++ b/lib/tasks/hashtags.rake@@ -0,0 +1,15 @@+# frozen_string_literal: true++desc "Mark posts with the old hashtag cooked format (pre enable_experimental_hashtag_autocomplete) for rebake"+task "hashtags:mark_old_format_for_rebake" => :environment do+ # See Post#rebake_old, which is called via the PeriodicalUpdates job+ # on a schedule.+ puts "Finding posts matching old format, this could take some time..."+ posts_to_rebake = Post.where("cooked like '%class=\"hashtag\"%'")+ STDOUT.puts(+ "[!] You are about to mark #{posts_to_rebake.count} posts containing hashtags in the old format to rebake. [CTRL+c] to cancel, [ENTER] to continue",+ )+ STDIN.gets.chomp if !Rails.env.test?+ posts_to_rebake.update_all(baked_version: 0)+ puts "Done, rebakes will happen when periodal updates job runs."+enddiff --git a/spec/tasks/hashtags_spec.rb b/spec/tasks/hashtags_spec.rbnew file mode 100644index 00000000000..0186174da3a--- /dev/null+++ b/spec/tasks/hashtags_spec.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++RSpec.describe "tasks/hashtags" do+ before do+ Rake::Task.clear+ Discourse::Application.load_tasks+ end++ describe "hashtag:mark_old_format_for_rebake" do+ fab!(:category) { Fabricate(:category, slug: "support") }++ before { SiteSetting.enable_experimental_hashtag_autocomplete = false }++ it "sets the baked_version to 0 for matching posts" do+ post_1 = Fabricate(:post, raw: "This is a cool #support hashtag")+ post_2 =+ Fabricate(+ :post,+ raw:+ "Some other thing which will not match <a class=\"hashtag-wow\">some weird custom thing</a>",+ )++ SiteSetting.enable_experimental_hashtag_autocomplete = true+ post_3 = Fabricate(:post, raw: "This is a cool #support hashtag")+ SiteSetting.enable_experimental_hashtag_autocomplete = false++ Rake::Task["hashtags:mark_old_format_for_rebake"].invoke++ [post_1, post_2, post_3].each(&:reload)++ expect(post_1.baked_version).to eq(0)+ expect(post_2.baked_version).to eq(Post::BAKED_VERSION)+ expect(post_3.baked_version).to eq(Post::BAKED_VERSION)+ end+ end+end