mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-10 08:03:28 +00:00
This change adds a simpler class for sentiment classification, replacing the soon-to-be removed `Classificator` hierarchy. Additionally, it adds a method for classifying concurrently, speeding up the backfill rake task.
22 lines
821 B
Ruby
22 lines
821 B
Ruby
# frozen_string_literal: true
|
|
|
|
desc "Backfill sentiment for all posts"
|
|
task "ai:sentiment:backfill", [:start_post] => [:environment] do |_, args|
|
|
public_categories = Category.where(read_restricted: false).pluck(:id)
|
|
|
|
Post
|
|
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
|
|
.joins(
|
|
"LEFT JOIN classification_results ON classification_results.target_id = posts.id AND classification_results.target_type = 'Post'",
|
|
)
|
|
.where("classification_results.target_id IS NULL")
|
|
.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 })
|
|
.find_in_batches do |batch|
|
|
print "."
|
|
DiscourseAi::Sentiment::PostClassification.new.bulk_classify!(batch)
|
|
end
|
|
end
|