1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-05 22:21:26 +00:00

Added memcached and set up cached items for up_matches page

This commit is contained in:
2015-12-17 18:44:24 +00:00
parent 127474da9c
commit 983cc9c667
7 changed files with 34 additions and 7 deletions

View File

@@ -66,8 +66,8 @@ class TournamentsController < ApplicationController
def up_matches
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
@mats = @tournament.mats.includes(:matches)
@matches = @tournament.cached_matches.select{|m| m.mat_id == nil}.sort_by{|m| m.bout_number}
@mats = @tournament.mats
end
def index
@@ -144,7 +144,7 @@ class TournamentsController < ApplicationController
def check_for_matches
if @tournament
if @tournament.matches.empty?
if @tournament.cached_matches.empty?
redirect_to "/tournaments/#{@tournament.id}/no_matches"
end
end

View File

@@ -18,6 +18,15 @@ class Mat < ActiveRecord::Base
end
end
def cached_matches
cache_timestamp = self.updated_at
cache_key = "matMatches|#{id}|#{cache_timestamp}"
Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
self.matches.includes(:wrestlers)
end
end
def assignNextMatch
t_matches = tournament.matches.select{|m| m.mat_id == nil}
if t_matches.size > 0
@@ -28,7 +37,7 @@ class Mat < ActiveRecord::Base
end
def unfinishedMatches
matches.select{|m| m.finished == nil}.sort_by{|m| m.bout_number}
cached_matches.select{|m| m.finished == nil}.sort_by{|m| m.bout_number}
end
end

View File

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

View File

@@ -9,7 +9,14 @@ class Tournament < ActiveRecord::Base
has_many :wrestlers, through: :weights
has_many :matches, dependent: :destroy
def cached_matches
cache_timestamp = self.updated_at
cache_key = "tournamentMatches|#{id}|#{cache_timestamp}"
Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
self.matches.includes(:wrestlers)
end
end
def tournament_types
["Pool to bracket"]