From db876809effdafa17f0913cd3ef34a34d32bc0ad Mon Sep 17 00:00:00 2001 From: jcwimer Date: Wed, 23 Dec 2015 14:11:20 +0000 Subject: [PATCH] Page caching set up --- Gemfile | 5 +- Gemfile.lock | 2 + app/models/match.rb | 6 +- app/views/tournaments/bracket.html.erb | 48 ++++---- app/views/tournaments/up_matches.html.erb | 134 +++++++++++----------- config/environments/production.rb | 8 ++ 6 files changed, 109 insertions(+), 94 deletions(-) diff --git a/Gemfile b/Gemfile index 49f494c..9ccbede 100644 --- a/Gemfile +++ b/Gemfile @@ -42,9 +42,10 @@ gem 'spring', :group => :development group :production do gem 'rails_12factor' gem 'mysql2' - gem 'passenger' - gem 'therubyracer' + gem 'passenger' + gem 'therubyracer' gem 'newrelic_rpm' + gem 'dalli' end #Other gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 1496c23..d17ca7a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,7 @@ GEM execjs coffee-script-source (1.9.1.1) concurrent-ruby (1.0.0) + dalli (2.7.5) devise (3.4.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -160,6 +161,7 @@ PLATFORMS DEPENDENCIES cancancan coffee-rails (~> 4.0.0) + dalli devise jbuilder (~> 2.0) jquery-rails diff --git a/app/models/match.rb b/app/models/match.rb index 64ce59b..70ce5f8 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,7 +1,7 @@ class Match < ActiveRecord::Base - belongs_to :tournament - belongs_to :weight - belongs_to :mat + belongs_to :tournament, touch: true + belongs_to :weight, touch: true + belongs_to :mat, touch: true has_many :wrestlers, :through => :weight after_save do diff --git a/app/views/tournaments/bracket.html.erb b/app/views/tournaments/bracket.html.erb index f1735ee..293be18 100644 --- a/app/views/tournaments/bracket.html.erb +++ b/app/views/tournaments/bracket.html.erb @@ -1,23 +1,25 @@ -
-
-
- -<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %> -
-
-

<%= @weight.max %> lbs Bracket

- -<%= render 'pool' %> - -<% if @bracketType == "twoPoolsToFinal" %> - <%= render 'twoPoolFinalBracket' %> -<% end %> -<% if @bracketType == "twoPoolsToSemi" %> - <%= render 'twoPoolSemiBracket' %> -<% end %> -<% if @bracketType == "fourPoolsToQuarter" %> - <%= render 'fourPoolQuarterBracket' %> -<% end %> -<% if @bracketType == "fourPoolsToSemi" %> - <%= render 'fourPoolSemiBracket' %> -<% end %> +<% cache ["brackets", @weight] do %> +
+
+
+ + <%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %> +
+
+

<%= @weight.max %> lbs Bracket

+ + <%= render 'pool' %> + + <% if @bracketType == "twoPoolsToFinal" %> + <%= render 'twoPoolFinalBracket' %> + <% end %> + <% if @bracketType == "twoPoolsToSemi" %> + <%= render 'twoPoolSemiBracket' %> + <% end %> + <% if @bracketType == "fourPoolsToQuarter" %> + <%= render 'fourPoolQuarterBracket' %> + <% end %> + <% if @bracketType == "fourPoolsToSemi" %> + <%= render 'fourPoolSemiBracket' %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tournaments/up_matches.html.erb b/app/views/tournaments/up_matches.html.erb index 929d3a0..3facce1 100644 --- a/app/views/tournaments/up_matches.html.erb +++ b/app/views/tournaments/up_matches.html.erb @@ -1,70 +1,72 @@ -<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default"%> - - -
-
-
This page reloads every 30s
-
-
-

Upcoming Matches

-
-
- - - - - - - - - - - - - <% @mats.each.map do |m| %> +<% cache ["up_matches", @tournament] do %> + <%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default"%> + + +
+
+
This page reloads every 30s
+
+
+

Upcoming Matches

+
+
+
MatOn MatOn DeckIn The HoleWarm Up
+ - - - - - + + + + + - <% end %> - -
<%= m.name %><% if m.unfinishedMatches.first %><%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %><% end %>
<% if m.unfinishedMatches.second %><%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %><% end %>
<% if m.unfinishedMatches.third %><%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %><% end %>
<% if m.unfinishedMatches.fourth %><%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %><% end %>
MatOn MatOn DeckIn The HoleWarm Up
-
-
-

Matches not assigned

-
-
- - - - - - - - - - - - <% if @matches.size > 0 %> - <% @matches.each.map do |m| %> + + + + <% @mats.each.map do |m| %> + + + + + + + + <% end %> + +
RoundBout NumberWeight ClassMatchup
<%= m.name %><% if m.unfinishedMatches.first %><%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %><% end %>
<% if m.unfinishedMatches.second %><%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %><% end %>
<% if m.unfinishedMatches.third %><%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %><% end %>
<% if m.unfinishedMatches.fourth %><%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %><% end %>
+
+
+

Matches not assigned

+
+
+ + - - - - + + + + - <% end %> - <% end %> - -
Round <%= m.round %><%= m.bout_number %><%= m.weight_max %> lbs<%= m.w1_name %> vs. <%= m.w2_name %>RoundBout NumberWeight ClassMatchup
- -
+ + + + <% if @matches.size > 0 %> + <% @matches.each.map do |m| %> + + Round <%= m.round %> + <%= m.bout_number %> + <%= m.weight_max %> lbs + <%= m.w1_name %> vs. <%= m.w2_name %> + + <% end %> + <% end %> + + + +
+<% end %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 543b8ff..03dd831 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -54,6 +54,14 @@ Wrestling::Application.configure do # Use a different cache store in production. # config.cache_store = :mem_cache_store + config.cache_store = :dalli_store, + (ENV["MEMCACHIER_SERVERS"] || "").split(","), + {:username => ENV["MEMCACHIER_USERNAME"], + :password => ENV["MEMCACHIER_PASSWORD"], + :failover => true, + :socket_timeout => 1.5, + :socket_failure_delay => 0.2 + } # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com"