2024-10-18 17:01:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ::Jobs
|
|
|
|
class HotTopicsGistBatch < ::Jobs::Base
|
2024-10-25 11:38:49 -04:00
|
|
|
def execute(_args)
|
2024-10-18 17:01:39 -04:00
|
|
|
return if !SiteSetting.discourse_ai_enabled
|
|
|
|
return if !SiteSetting.ai_summarization_enabled
|
|
|
|
return if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
|
|
|
|
|
|
|
|
Topic
|
|
|
|
.joins("JOIN topic_hot_scores on topics.id = topic_hot_scores.topic_id")
|
|
|
|
.order("topic_hot_scores.score DESC")
|
|
|
|
.limit(SiteSetting.ai_summarize_max_hot_topics_gists_per_batch)
|
|
|
|
.each do |topic|
|
|
|
|
summarizer = DiscourseAi::Summarization.topic_gist(topic)
|
|
|
|
gist = summarizer.existing_summary
|
|
|
|
|
2024-10-25 11:38:49 -04:00
|
|
|
summarizer.force_summarize(Discourse.system_user) if gist.blank? || gist.outdated
|
2024-10-18 17:01:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|