Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

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

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions lib/automation/report_context_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,11 @@ def initialize(
@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)
Expand All @@ -97,9 +91,7 @@ def format_post(post)
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}"
Expand Down
5 changes: 1 addition & 4 deletions spec/lib/modules/automation/report_context_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ module Automation

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)

Expand Down
Loading