FIX: Filter soft-deleted topics when backfilling sentiment (#527)

This commit is contained in:
Roman Rizzi 2024-03-12 21:01:24 -03:00 committed by GitHub
parent 1c90ad81c2
commit c4ead89c6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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 "."

View File

@ -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