FIX: indirect assigned to in search (#266)

Search similarly to topic list should return a hash with post_number
This commit is contained in:
Krzysztof Kotlarek 2021-12-13 15:47:09 +01:00 committed by GitHub
parent 1a1dffc5e8
commit a9ef43e12f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -252,7 +252,7 @@ after_initialize do
if allowed_access && results.posts.length > 0 if allowed_access && results.posts.length > 0
topics = results.posts.map(&:topic) topics = results.posts.map(&:topic)
assignments = Assignment.strict_loading.where(topic: topics).includes(:assigned_to).group_by(&:topic_id) assignments = Assignment.strict_loading.where(topic: topics, active: true).includes(:assigned_to, :target).group_by(&:topic_id)
results.posts.each do |post| results.posts.each do |post|
topic_assignments = assignments[post.topic.id] topic_assignments = assignments[post.topic.id]
@ -264,7 +264,9 @@ after_initialize do
end end
if indirect_assignments.present? if indirect_assignments.present?
indirect_assignment_map = indirect_assignments.reduce({}) do |acc, assignment| indirect_assignment_map = indirect_assignments.reduce({}) do |acc, assignment|
acc[assignment.target_id] = assignment.assigned_to if assignment.target
acc[assignment.target_id] = { assigned_to: assignment.assigned_to, post_number: assignment.target.post_number }
end
acc acc
end end
post.topic.preload_indirectly_assigned_to(indirect_assignment_map) post.topic.preload_indirectly_assigned_to(indirect_assignment_map)