diff --git a/lib/automation/report_context_generator.rb b/lib/automation/report_context_generator.rb index b0e2d10d..d15eac80 100644 --- a/lib/automation/report_context_generator.rb +++ b/lib/automation/report_context_generator.rb @@ -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}" diff --git a/spec/lib/modules/automation/report_context_generator_spec.rb b/spec/lib/modules/automation/report_context_generator_spec.rb index e1a7df5d..c999b91d 100644 --- a/spec/lib/modules/automation/report_context_generator_spec.rb +++ b/spec/lib/modules/automation/report_context_generator_spec.rb @@ -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)