mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-05-06 14:33:14 +00:00
Fixed a number of N+1 issues on low traffic pages. I also added relevant html tests for these pages.
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
{
|
||||
"tournament": {
|
||||
"attributes": <%= @tournament.attributes.to_json %>,
|
||||
<%
|
||||
wrestlers_by_id = @tournament.wrestlers.index_by(&:id)
|
||||
weights_by_id = @tournament.weights.index_by(&:id)
|
||||
mats_by_id = @tournament.mats.index_by(&:id)
|
||||
sorted_matches = @tournament.matches.sort_by(&:bout_number)
|
||||
%>
|
||||
{
|
||||
"tournament": {
|
||||
"attributes": <%= @tournament.attributes.to_json %>,
|
||||
"schools": <%= @tournament.schools.map(&:attributes).to_json %>,
|
||||
"weights": <%= @tournament.weights.map(&:attributes).to_json %>,
|
||||
"mats": <%= @tournament.mats.map { |mat| mat.attributes.merge(
|
||||
@@ -14,14 +20,14 @@
|
||||
"weight": wrestler.weight&.attributes
|
||||
}
|
||||
) }.to_json %>,
|
||||
"matches": <%= @tournament.matches.sort_by(&:bout_number).map { |match| match.attributes.merge(
|
||||
{
|
||||
"w1_name": Wrestler.find_by(id: match.w1)&.name,
|
||||
"w2_name": Wrestler.find_by(id: match.w2)&.name,
|
||||
"winner_name": Wrestler.find_by(id: match.winner_id)&.name,
|
||||
"weight": Weight.find_by(id: match.weight_id)&.attributes,
|
||||
"mat": Mat.find_by(id: match.mat_id)&.attributes
|
||||
}
|
||||
) }.to_json %>
|
||||
}
|
||||
"matches": <%= sorted_matches.map { |match| match.attributes.merge(
|
||||
{
|
||||
"w1_name": wrestlers_by_id[match.w1]&.name,
|
||||
"w2_name": wrestlers_by_id[match.w2]&.name,
|
||||
"winner_name": wrestlers_by_id[match.winner_id]&.name,
|
||||
"weight": weights_by_id[match.weight_id]&.attributes,
|
||||
"mat": mats_by_id[match.mat_id]&.attributes
|
||||
}
|
||||
) }.to_json %>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user