1
0
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:
2026-02-17 22:27:11 -05:00
parent d359be3ea1
commit 8670ce38c3
16 changed files with 330 additions and 103 deletions

View File

@@ -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 %>
}
}