From c4ead89c6b2276ee9139a41c3027c9c3adacb098 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Tue, 12 Mar 2024 21:01:24 -0300 Subject: [PATCH] FIX: Filter soft-deleted topics when backfilling sentiment (#527) --- lib/tasks/modules/sentiment/backfill.rake | 1 + spec/tasks/backfill_spec.rb | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 spec/tasks/backfill_spec.rb diff --git a/lib/tasks/modules/sentiment/backfill.rake b/lib/tasks/modules/sentiment/backfill.rake index 0e14bf52..30d43e43 100644 --- a/lib/tasks/modules/sentiment/backfill.rake +++ b/lib/tasks/modules/sentiment/backfill.rake @@ -13,6 +13,7 @@ task "ai:sentiment:backfill", [:start_post] => [:environment] do |_, args| .where("posts.id >= ?", args[:start_post].to_i || 0) .where("category_id IN (?)", public_categories) .where(posts: { deleted_at: nil }) + .where(topics: { deleted_at: nil }) .order("posts.id ASC") .find_each do |post| print "." diff --git a/spec/tasks/backfill_spec.rb b/spec/tasks/backfill_spec.rb new file mode 100644 index 00000000..7c0d51ce --- /dev/null +++ b/spec/tasks/backfill_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "../support/sentiment_inference_stubs" + +RSpec.describe "assets:precompile" do + before do + Rake::Task.clear + Discourse::Application.load_tasks + end + + describe "ai:sentiment:backfill" do + before { SiteSetting.ai_sentiment_inference_service_api_endpoint = "http://test.com" } + + it "does nothing if the topic is soft-deleted" do + target = Fabricate(:post) + SentimentInferenceStubs.stub_classification(target) + target.topic.trash! + + path = Rake::Task["ai:sentiment:backfill"].invoke + + expect(ClassificationResult.count).to be_zero + end + end +end