FIX: Don't regenerate up to date gists (#843)

This commit is contained in:
Roman Rizzi 2024-10-18 18:49:01 -03:00 committed by GitHub
parent 27b5542357
commit e768fa877e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

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

View File

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