Minimize creation of CacheBuster objects (#599)

This commit is contained in:
Arun Kumar 2018-07-24 12:30:30 -05:00 committed by Ben Halpern
parent cd17261963
commit 876c70d2bb
10 changed files with 51 additions and 39 deletions

View file

@ -477,9 +477,10 @@ class Article < ApplicationRecord
def bust_cache
if Rails.env.production?
CacheBuster.new.bust(path)
CacheBuster.new.bust(path + "?i=i")
CacheBuster.new.bust(path + "?preview=" + password)
cache_buster = CacheBuster.new
cache_buster.bust(path)
cache_buster.bust(path + "?i=i")
cache_buster.bust(path + "?preview=" + password)
async_bust
end
end

View file

@ -22,7 +22,8 @@ class Badge < ApplicationRecord
end
def bust_path
CacheBuster.new.bust path
CacheBuster.new.bust path + "?i=i"
cache_buster = CacheBuster.new
cache_buster.bust path
cache_buster.bust path + "?i=i"
end
end

View file

@ -305,8 +305,9 @@ class Comment < ApplicationRecord
def bust_cache
expire_root_fragment
CacheBuster.new.bust("#{commentable.path}") if commentable
CacheBuster.new.bust("#{commentable.path}/comments") if commentable
cache_buster = CacheBuster.new
cache_buster.bust("#{commentable.path}") if commentable
cache_buster.bust("#{commentable.path}/comments") if commentable
async_bust
end

View file

@ -47,7 +47,8 @@ class Event < ApplicationRecord
end
def bust_cache
CacheBuster.new.bust("/events")
CacheBuster.new.bust("/events?i=i")
cache_buster = CacheBuster.new
cache_buster.bust("/events")
cache_buster.bust("/events?i=i")
end
end

View file

@ -71,9 +71,10 @@ class Organization < ApplicationRecord
end
def resave_articles
cache_buster = CacheBuster.new
articles.each do |article|
CacheBuster.new.bust(article.path)
CacheBuster.new.bust(article.path + "?i=i")
cache_buster.bust(article.path)
cache_buster.bust(article.path + "?i=i")
article.save
end
end
@ -98,10 +99,11 @@ class Organization < ApplicationRecord
end
def bust_cache
CacheBuster.new.bust("/#{slug}")
cache_buster = CacheBuster.new
cache_buster.bust("/#{slug}")
begin
articles.each do |article|
CacheBuster.new.bust(article.path)
cache_buster.bust(article.path)
end
rescue
puts "Tag issue"

View file

@ -127,10 +127,11 @@ class PodcastEpisode < ApplicationRecord
purge
purge_all
begin
CacheBuster.new.bust(path)
CacheBuster.new.bust("/"+podcast_slug)
CacheBuster.new.bust("/pod")
CacheBuster.new.bust(path)
cache_buster = CacheBuster.new
cache_buster.bust(path)
cache_buster.bust("/"+podcast_slug)
cache_buster.bust("/pod")
cache_buster.bust(path)
rescue
end

View file

@ -70,15 +70,16 @@ class Reaction < ApplicationRecord
private
def update_reactable
cache_buster = CacheBuster.new
if reactable_type == "Article"
reactable.async_score_calc
reactable.index!
CacheBuster.new.bust "/reactions/logged_out_reaction_counts?article_id=#{reactable_id}"
cache_buster.bust "/reactions/logged_out_reaction_counts?article_id=#{reactable_id}"
elsif reactable_type == "Comment"
reactable.save
CacheBuster.new.bust "/reactions/logged_out_reaction_counts?commentable_id=#{reactable.commentable_id}&commentable_type=#{reactable.commentable_type}"
cache_buster.bust "/reactions/logged_out_reaction_counts?commentable_id=#{reactable.commentable_id}&commentable_type=#{reactable.commentable_type}"
end
CacheBuster.new.bust user.path
cache_buster.bust user.path
occasionally_sync_reaction_counts
end
handle_asynchronously :update_reactable
@ -92,10 +93,11 @@ class Reaction < ApplicationRecord
featured_articles = Article.where(featured: true).order('hotness_score DESC').limit(3).pluck(:id)
if featured_articles.include?(reactable.id)
reactable.touch
CacheBuster.new.bust "/"
CacheBuster.new.bust "/"
CacheBuster.new.bust "/?i=i"
CacheBuster.new.bust "?i=i"
cache_buster = CacheBuster.new
cache_buster.bust "/"
cache_buster.bust "/"
cache_buster.bust "/?i=i"
cache_buster.bust "?i=i"
end
end
handle_asynchronously :async_bust

View file

@ -41,11 +41,12 @@ class Tag < ActsAsTaggableOn::Tag
end
def bust_cache
CacheBuster.new.bust("/t/#{name}")
CacheBuster.new.bust("/t/#{name}?i=i")
CacheBuster.new.bust("/t/#{name}/?i=i")
CacheBuster.new.bust("/t/#{name}/")
CacheBuster.new.bust("/tags")
cache_buster = CacheBuster.new
cache_buster.bust("/t/#{name}")
cache_buster.bust("/t/#{name}?i=i")
cache_buster.bust("/t/#{name}/?i=i")
cache_buster.bust("/t/#{name}/")
cache_buster.bust("/tags")
end
def validate_alias

View file

@ -308,9 +308,10 @@ class User < ApplicationRecord
end
def resave_articles
cache_buster = CacheBuster.new
articles.each do |article|
CacheBuster.new.bust(article.path)
CacheBuster.new.bust(article.path + "?i=i")
cache_buster.bust(article.path)
cache_buster.bust(article.path + "?i=i")
article.save
end
end

View file

@ -7,14 +7,15 @@ task :get_podcast_episodes => :environment do
end
task :periodic_cache_bust => :environment do
CacheBuster.new.bust("/enter")
CacheBuster.new.bust("/new")
CacheBuster.new.bust("/dashboard")
CacheBuster.new.bust("/users/auth/twitter")
CacheBuster.new.bust("/users/auth/github")
CacheBuster.new.bust("/feed")
CacheBuster.new.bust("/feed")
CacheBuster.new.bust("/feed.xml")
cache_buster = CacheBuster.new
cache_buster.bust("/enter")
cache_buster.bust("/new")
cache_buster.bust("/dashboard")
cache_buster.bust("/users/auth/twitter")
cache_buster.bust("/users/auth/github")
cache_buster.bust("/feed")
cache_buster.bust("/feed")
cache_buster.bust("/feed.xml")
end
task :hourly_bust => :environment do