mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Ensuring good caching for the most popular pages. Added tests.
This commit is contained in:
13
app/views/schools/_wrestler_row_cells.html.erb
Normal file
13
app/views/schools/_wrestler_row_cells.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<% if local_assigns[:school_permission_key].present? %>
|
||||
<% wrestler_path_with_key = wrestler_path(wrestler) %>
|
||||
<% wrestler_path_with_key += "?school_permission_key=#{school_permission_key}" %>
|
||||
<td><%= link_to wrestler.name, wrestler_path_with_key %></td>
|
||||
<% else %>
|
||||
<td><%= link_to wrestler.name, wrestler_path(wrestler) %></td>
|
||||
<% end %>
|
||||
<td><%= wrestler.weight.max %></td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %> <%= wrestler.criteria %></td>
|
||||
<td><%= wrestler.original_seed %></td>
|
||||
<td><%= wrestler.total_team_points - wrestler.total_points_deducted %></td>
|
||||
<td><%= "Yes" if wrestler.extra? %></td>
|
||||
<td><%= wrestler.next_match_bout_number %> <%= wrestler.next_match_mat_name %></td>
|
||||
@@ -54,19 +54,8 @@
|
||||
<tbody>
|
||||
<% @wrestlers.sort_by { |w| w.weight.max }.each do |wrestler| %>
|
||||
<% if params[:school_permission_key].present? %>
|
||||
<!-- No caching when school_permission_key is present -->
|
||||
<tr>
|
||||
<td>
|
||||
<% wrestler_path_with_key = wrestler_path(wrestler) %>
|
||||
<% wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
|
||||
<%= link_to wrestler.name, wrestler_path_with_key %>
|
||||
</td>
|
||||
<td><%= wrestler.weight.max %></td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %> <%= wrestler.criteria %></td>
|
||||
<td><%= wrestler.original_seed %></td>
|
||||
<td><%= wrestler.total_team_points - wrestler.total_points_deducted %></td>
|
||||
<td><%= "Yes" if wrestler.extra? %></td>
|
||||
<td><%= wrestler.next_match_bout_number %> <%= wrestler.next_match_mat_name %></td>
|
||||
<%= render "schools/wrestler_row_cells", wrestler: wrestler, school_permission_key: params[:school_permission_key] %>
|
||||
|
||||
<% if can? :manage, wrestler.school %>
|
||||
<td>
|
||||
@@ -86,34 +75,21 @@
|
||||
<% end %>
|
||||
</tr>
|
||||
<% else %>
|
||||
<!-- Use caching only when school_permission_key is NOT present -->
|
||||
<% cache ["#{wrestler.id}_school_show", @school] do %>
|
||||
<tr>
|
||||
<td><%= link_to wrestler.name, wrestler_path(wrestler) %></td>
|
||||
<td><%= wrestler.weight.max %></td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %> <%= wrestler.criteria %></td>
|
||||
<td><%= wrestler.original_seed %></td>
|
||||
<td><%= wrestler.total_team_points - wrestler.total_points_deducted %></td>
|
||||
<td><%= "Yes" if wrestler.extra? %></td>
|
||||
<td><%= wrestler.next_match_bout_number %> <%= wrestler.next_match_mat_name %></td>
|
||||
<% end %>
|
||||
<% if can? :manage, wrestler.school %>
|
||||
<td>
|
||||
<% edit_wrestler_path_with_key = edit_wrestler_path(wrestler) %>
|
||||
<% edit_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
|
||||
|
||||
<% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
|
||||
<% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
|
||||
|
||||
<%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<% cache ["school_show_wrestler_cells", wrestler] do %>
|
||||
<%= render "schools/wrestler_row_cells", wrestler: wrestler %>
|
||||
<% end %>
|
||||
<% if can? :manage, wrestler.school %>
|
||||
<td>
|
||||
<%= link_to edit_wrestler_path(wrestler), class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to wrestler_path(wrestler), data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<% @final_match.each do |match| %>
|
||||
<div class="round">
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><p><%= match.bout_number %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% else %>
|
||||
<div class="bout-number"><p><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% end %>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<% cache ["bracket_final_match", match, match.wrestler1, match.wrestler2, @winner_place, params[:print].to_s] do %>
|
||||
<div class="round">
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><p><%= match.bout_number %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% else %>
|
||||
<div class="bout-number"><p><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% end %>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<div class="round">
|
||||
<% @round_matches.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </div>
|
||||
<% else %>
|
||||
<div class="bout-number"><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %> </div>
|
||||
<% end %>
|
||||
<div class="bout-number">Round <%= match.round %></div>
|
||||
<div class="bout-number"><%= match.bracket_position %></div>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
<% cache ["bracket_round_match", match, match.wrestler1, match.wrestler2, params[:print].to_s] do %>
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </div>
|
||||
<% else %>
|
||||
<div class="bout-number"><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %> </div>
|
||||
<% end %>
|
||||
<div class="bout-number">Round <%= match.round %></div>
|
||||
<div class="bout-number"><%= match.bracket_position %></div>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
6
app/views/tournaments/_team_score_row.html.erb
Normal file
6
app/views/tournaments/_team_score_row.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% cache ["team_score_row", school, rank] do %>
|
||||
<tr>
|
||||
<td><%= rank %>. <%= school.name %> (<%= school.abbreviation %>)</td>
|
||||
<td><%= school.page_score_string %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -31,14 +31,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% (local_assigns[:matches] || tournament.up_matches_unassigned_matches).each do |m| %>
|
||||
<tr>
|
||||
<td>Round <%= m.round %></td>
|
||||
<td><%= m.bout_number %></td>
|
||||
<td><%= m.weight_max %></td>
|
||||
<td><%= m.w1_bracket_name %> vs. <%= m.w2_bracket_name %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<%= render partial: "tournaments/up_matches_unassigned_row", collection: (local_assigns[:matches] || tournament.up_matches_unassigned_matches), as: :match %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<% queue1_match, queue2_match, queue3_match, queue4_match = mat.queue_matches %>
|
||||
<% cache ["up_matches_mat_row", mat, mat.queue1, mat.queue2, mat.queue3, mat.queue4] do %>
|
||||
<% queue_match_dependencies = [queue1_match, queue2_match, queue3_match, queue4_match].compact.flat_map { |match| [match, match.wrestler1, match.wrestler2] } %>
|
||||
<% cache ["up_matches_mat_row", mat, *queue_match_dependencies] do %>
|
||||
<tr>
|
||||
<td><%= mat.name %></td>
|
||||
<td>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<% cache ["up_matches_unassigned_row", match, match.wrestler1, match.wrestler2] do %>
|
||||
<tr>
|
||||
<td>Round <%= match.round %></td>
|
||||
<td><%= match.bout_number %></td>
|
||||
<td><%= match.weight_max %></td>
|
||||
<td><%= match.w1_bracket_name %> vs. <%= match.w2_bracket_name %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -1,8 +1,8 @@
|
||||
<% cache ["#{@weight.id}_bracket", @weight] do %>
|
||||
<% cache ["#{@weight.id}_bracket", @weight, params[:print].to_s] do %>
|
||||
<%= render 'bracket_partial' %>
|
||||
<% end %>
|
||||
<% if @tournament.tournament_type == "Pool to bracket" %>
|
||||
<%= render 'pool_bracket_director_actions' %>
|
||||
<% elsif @tournament.tournament_type.include? "Modified 16 Man Double Elimination" or @tournament.tournament_type.include? "Regular Double Elimination" %>
|
||||
<%= render 'bracket_director_actions' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
<% cache ["#{@tournament.id}_team_scores", @tournament] do %>
|
||||
|
||||
<% team_scores_last_updated = @schools.map(&:updated_at).compact.max&.utc&.to_fs(:nsec) %>
|
||||
<% cache ["team_scores", @tournament.id, @schools.size, team_scores_last_updated] do %>
|
||||
<table class="pagebreak table table-striped table-bordered">
|
||||
<h3>Team Scores</h3>
|
||||
<thead>
|
||||
@@ -11,12 +10,9 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @schools.each do |school| %>
|
||||
<tr>
|
||||
<td><%= @schools.index(school) + 1 %>. <%= school.name %> (<%= school.abbreviation %>)</td>
|
||||
<td><%= school.page_score_string %></td>
|
||||
</tr>
|
||||
<% @schools.each_with_index do |school, index| %>
|
||||
<%= render "tournaments/team_score_row", school: school, rank: index + 1 %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
10
app/views/weights/_readonly_wrestler_row.html.erb
Normal file
10
app/views/weights/_readonly_wrestler_row.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<% cache ["weight_show_wrestler_row", wrestler] do %>
|
||||
<tr>
|
||||
<td><%= link_to wrestler.name, wrestler %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td><%= wrestler.original_seed %></td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
|
||||
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
|
||||
<td><%= "Yes" if wrestler.extra? %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -14,35 +14,36 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= link_to "#{wrestler.name}", wrestler %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||
<%= w.text_field :original_seed %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= wrestler.original_seed %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
|
||||
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
|
||||
<td><% if wrestler.extra? == true %>
|
||||
Yes
|
||||
<% end %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
<%= link_to wrestler, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% sorted_wrestlers = @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]} %>
|
||||
<% if can? :manage, @tournament %>
|
||||
<% sorted_wrestlers.each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= link_to wrestler.name, wrestler %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td>
|
||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||
<%= w.text_field :original_seed %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
|
||||
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
|
||||
<td><%= "Yes" if wrestler.extra? %></td>
|
||||
<td>
|
||||
<%= link_to wrestler, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% sorted_wrestlers.each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<%= render "weights/readonly_wrestler_row", wrestler: wrestler %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random bracket line.</p>
|
||||
|
||||
Reference in New Issue
Block a user