DEV: Update solved report due to changes in solved plugin (#1212)

This commit is contained in:
Natalie Tay 2025-03-25 15:15:30 +08:00 committed by GitHub
parent 1dde82eb58
commit f7536181af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 17 deletions

View File

@ -65,17 +65,11 @@ module DiscourseAi
@posts = @posts.where(topic_id: topic_ids_with_tags)
end
@solutions = {}
if defined?(::DiscourseSolved)
TopicCustomField
.where(name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD)
@solutions =
DiscourseSolved::SolvedTopic
.where(topic_id: @posts.select(:topic_id))
.pluck(:topic_id, :value)
.each do |topic_id, post_id|
@solutions[topic_id] ||= Set.new
@solutions[topic_id] << post_id.to_i
end
end
.pluck(:topic_id, :answer_post_id)
.to_h
end
def format_topic(topic)
@ -97,9 +91,7 @@ module DiscourseAi
buffer = []
buffer << ""
buffer << "post_number: #{post.post_number}"
if @solutions.key?(post.topic_id) && @solutions[post.topic_id].include?(post.id)
buffer << "solution: true"
end
buffer << "solution: true" if @solutions[post.topic_id] == post.id
buffer << post.created_at.strftime("%Y-%m-%d %H:%M")
buffer << "user: #{post.user&.username}"
buffer << "likes: #{post.like_count}"

View File

@ -45,10 +45,7 @@ module DiscourseAi
if defined?(::DiscourseSolved)
it "will correctly denote solved topics" do
topic_with_likes.custom_fields[
::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
] = post_with_likes2.id
topic_with_likes.save_custom_fields
Fabricate(:solved_topic, topic: topic_with_likes, answer_post: post_with_likes2)
context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)