diff --git a/app/models/article.rb b/app/models/article.rb index e7e076f3d..6d7f3e108 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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 diff --git a/app/models/badge.rb b/app/models/badge.rb index af7cef87a..4aac5d82e 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -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 diff --git a/app/models/comment.rb b/app/models/comment.rb index 549d13be5..99bc1da9f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 550288c52..78cbda915 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/models/organization.rb b/app/models/organization.rb index 68f5ef40a..1a2556836 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -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" diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index 503adc7af..980084cd1 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -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 diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 38cefb94b..eaab8ccf8 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index af8c1b253..cecc449c0 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 183003195..ddaabeb42 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/lib/tasks/fetch.rake b/lib/tasks/fetch.rake index fc769d9ed..690c0bdde 100644 --- a/lib/tasks/fetch.rake +++ b/lib/tasks/fetch.rake @@ -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