diff --git a/app/jobs/regular/hot_topics_gist_batch.rb b/app/jobs/regular/hot_topics_gist_batch.rb index e6513104..b5ff3a7e 100644 --- a/app/jobs/regular/hot_topics_gist_batch.rb +++ b/app/jobs/regular/hot_topics_gist_batch.rb @@ -15,9 +15,11 @@ module ::Jobs summarizer = DiscourseAi::Summarization.topic_gist(topic) gist = summarizer.existing_summary - summarizer.delete_cached_summaries! if gist && gist.outdated + if gist.blank? || gist.outdated + summarizer.delete_cached_summaries! - summarizer.summarize(Discourse.system_user) + summarizer.summarize(Discourse.system_user) + end end end end diff --git a/spec/jobs/regular/hot_topics_gist_batch_spec.rb b/spec/jobs/regular/hot_topics_gist_batch_spec.rb index faa137d1..2e0e7ee3 100644 --- a/spec/jobs/regular/hot_topics_gist_batch_spec.rb +++ b/spec/jobs/regular/hot_topics_gist_batch_spec.rb @@ -61,10 +61,15 @@ RSpec.describe Jobs::HotTopicsGistBatch do end it "does nothing if the gist is up to date" do - subject.execute({}) + updated_gist = "They updated me :(" + + DiscourseAi::Completions::Llm.with_prepared_responses([updated_gist]) do + subject.execute({}) + end gist = AiSummary.gist.find_by(target: topic_1) - expect(gist.summarized_text).to eq(ai_gist.summarized_text) + expect(AiSummary.gist.where(target: topic_1).count).to eq(1) + expect(gist.summarized_text).not_to eq(updated_gist) expect(gist.original_content_sha).to eq(ai_gist.original_content_sha) end