Use config_for for cache buster values (#34851)
				
					
				
			This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
# This configuration was generated by
 | 
			
		||||
# `rubocop --auto-gen-config --auto-gen-only-exclude --no-offense-counts --no-auto-gen-timestamp`
 | 
			
		||||
# using RuboCop version 1.75.7.
 | 
			
		||||
# using RuboCop version 1.75.8.
 | 
			
		||||
# The point is for the user to remove these configuration records
 | 
			
		||||
# one by one as the offenses are removed from the code base.
 | 
			
		||||
# Note that changes in the inspected code, or installation of new
 | 
			
		||||
@@ -37,7 +37,6 @@ Style/FetchEnvVar:
 | 
			
		||||
  Exclude:
 | 
			
		||||
    - 'config/initializers/2_limited_federation_mode.rb'
 | 
			
		||||
    - 'config/initializers/3_omniauth.rb'
 | 
			
		||||
    - 'config/initializers/cache_buster.rb'
 | 
			
		||||
    - 'config/initializers/paperclip.rb'
 | 
			
		||||
    - 'lib/tasks/repo.rake'
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -417,7 +417,7 @@ class MediaAttachment < ApplicationRecord
 | 
			
		||||
 | 
			
		||||
  # Record the cache keys to burst before the file get actually deleted
 | 
			
		||||
  def prepare_cache_bust!
 | 
			
		||||
    return unless Rails.configuration.x.cache_buster_enabled
 | 
			
		||||
    return unless Rails.configuration.x.cache_buster.enabled
 | 
			
		||||
 | 
			
		||||
    @paths_to_cache_bust = MediaAttachment.attachment_definitions.keys.flat_map do |attachment_name|
 | 
			
		||||
      attachment = public_send(attachment_name)
 | 
			
		||||
@@ -434,7 +434,7 @@ class MediaAttachment < ApplicationRecord
 | 
			
		||||
  # Once Paperclip has deleted the files, we can't recover the cache keys,
 | 
			
		||||
  # so use the previously-saved ones
 | 
			
		||||
  def bust_cache!
 | 
			
		||||
    return unless Rails.configuration.x.cache_buster_enabled
 | 
			
		||||
    return unless Rails.configuration.x.cache_buster.enabled
 | 
			
		||||
 | 
			
		||||
    CacheBusterWorker.push_bulk(@paths_to_cache_bust) { |path| [path] }
 | 
			
		||||
  rescue => e
 | 
			
		||||
 
 | 
			
		||||
@@ -95,7 +95,7 @@ class SuspendAccountService < BaseService
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          CacheBusterWorker.perform_async(attachment.url(style)) if Rails.configuration.x.cache_buster_enabled
 | 
			
		||||
          CacheBusterWorker.perform_async(attachment.url(style)) if Rails.configuration.x.cache_buster.enabled
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -91,7 +91,7 @@ class UnsuspendAccountService < BaseService
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          CacheBusterWorker.perform_async(attachment.url(style)) if Rails.configuration.x.cache_buster_enabled
 | 
			
		||||
          CacheBusterWorker.perform_async(attachment.url(style)) if Rails.configuration.x.cache_buster.enabled
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 
 | 
			
		||||
@@ -103,6 +103,7 @@ module Mastodon
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    config.x.cache_buster = config_for(:cache_buster)
 | 
			
		||||
    config.x.captcha = config_for(:captcha)
 | 
			
		||||
    config.x.mastodon = config_for(:mastodon)
 | 
			
		||||
    config.x.translation = config_for(:translation)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								config/cache_buster.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								config/cache_buster.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
shared:
 | 
			
		||||
  enabled: <%= ENV.fetch('CACHE_BUSTER_ENABLED', 'false') == 'true' %>
 | 
			
		||||
  secret_header: <%= ENV.fetch('CACHE_BUSTER_SECRET_HEADER', nil) %>
 | 
			
		||||
  secret: <%= ENV.fetch('CACHE_BUSTER_SECRET', nil) %>
 | 
			
		||||
  http_method: <%= ENV.fetch('CACHE_BUSTER_HTTP_METHOD', 'GET') %>
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
Rails.application.configure do
 | 
			
		||||
  config.x.cache_buster_enabled = ENV['CACHE_BUSTER_ENABLED'] == 'true'
 | 
			
		||||
 | 
			
		||||
  config.x.cache_buster = {
 | 
			
		||||
    secret_header: ENV['CACHE_BUSTER_SECRET_HEADER'],
 | 
			
		||||
    secret: ENV['CACHE_BUSTER_SECRET'],
 | 
			
		||||
    http_method: ENV['CACHE_BUSTER_HTTP_METHOD'] || 'GET',
 | 
			
		||||
  }
 | 
			
		||||
end
 | 
			
		||||
@@ -291,7 +291,7 @@ RSpec.describe MediaAttachment, :attachment_processing do
 | 
			
		||||
    let(:media) { Fabricate(:media_attachment) }
 | 
			
		||||
 | 
			
		||||
    before do
 | 
			
		||||
      allow(Rails.configuration.x).to receive(:cache_buster_enabled).and_return(true)
 | 
			
		||||
      allow(Rails.configuration.x.cache_buster).to receive(:enabled).and_return(true)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'queues CacheBusterWorker jobs' do
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ RSpec.describe SuspendAccountService do
 | 
			
		||||
 | 
			
		||||
    before do
 | 
			
		||||
      allow(FeedManager.instance).to receive_messages(unmerge_from_home: nil, unmerge_from_list: nil)
 | 
			
		||||
      allow(Rails.configuration.x).to receive(:cache_buster_enabled).and_return(true)
 | 
			
		||||
      allow(Rails.configuration.x.cache_buster).to receive(:enabled).and_return(true)
 | 
			
		||||
 | 
			
		||||
      local_follower.follow!(account)
 | 
			
		||||
      list.accounts << account
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user