1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Fixed n+1 error for matches page on tournament

This commit is contained in:
2021-11-08 22:42:55 +00:00
parent 7ee8abe81a
commit ad259f00b5
3 changed files with 4 additions and 3 deletions

View File

@@ -134,7 +134,7 @@ class TournamentsController < ApplicationController
end
def matches
@matches = @tournament.matches.sort_by{|m| m.bout_number}
@matches = @tournament.matches.includes(:wrestlers,:schools).sort_by{|m| m.bout_number}
if @match
@w1 = @match.wrestler1
@w2 = @match.wrestler2

View File

@@ -3,6 +3,7 @@ class Match < ActiveRecord::Base
belongs_to :weight, touch: true
belongs_to :mat, touch: true
has_many :wrestlers, :through => :weight
has_many :schools, :through => :wrestlers
after_update :after_finished_actions, :if => :saved_change_to_finished? or :saved_change_to_winner_id? or :saved_change_to_win_type? or :saved_change_to_score?
def after_finished_actions

View File

@@ -10,8 +10,8 @@ class Weight < ActiveRecord::Base
# passed via layouts/_tournament-navbar.html.erb
# tournaments controller does a .split(',') on this string and creates an array via commas
# tournament model runs the code via method create_pre_defined_weights
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,145,152,160,170,182,195,220,285"
HS_GIRLS_WEIGHT_CLASSES = "101,106,111,116,121,126,131,137,143,150,160,170,189,235"
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,144,150,157,165,175,190,215,285."
HS_GIRLS_WEIGHT_CLASSES = "100,105,110,115,120,125,130,135,140,145,155,170,190,235"
before_destroy do
self.tournament.destroy_all_matches