FIX: deprecation warning - initialization autoloaded the constant (#12400)

Get rid of deprecation related to Zeitwerk autoloader.

Original PR was reverted because of multisite bug #12381 - thank you @davidtaylorhq for fixing it.

I added the last commit to fix that multisite problem.
This commit is contained in:
Krzysztof Kotlarek
2021-03-16 09:47:57 +11:00
committed by GitHub
parent ddf8e9b6b6
commit e10a74694a
6 changed files with 169 additions and 150 deletions

View File

@@ -55,6 +55,8 @@ require 'pry-rails' if Rails.env.development?
require 'discourse_fonts' require 'discourse_fonts'
require_relative '../lib/zeitwerk_config.rb'
if defined?(Bundler) if defined?(Bundler)
bundler_groups = [:default] bundler_groups = [:default]
@@ -116,6 +118,7 @@ module Discourse
config.autoload_paths += Dir["#{config.root}/lib/validators/"] config.autoload_paths += Dir["#{config.root}/lib/validators/"]
Rails.autoloaders.main.ignore(Dir["#{config.root}/app/models/reports"]) Rails.autoloaders.main.ignore(Dir["#{config.root}/app/models/reports"])
Rails.autoloaders.main.ignore(Dir["#{config.root}/lib/freedom_patches"])
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named. # :all can be used as a placeholder for all plugins not explicitly named.

View File

@@ -1,5 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
# Multisite freedom patch defines RailsMultisite::DiscoursePatches.config which is used by 200-first_middlewares.rb
# Therefore it can not be postponed with .to_prepare
RUN_WITHOUT_PREPARE = ["#{Rails.root}/lib/freedom_patches/rails_multisite.rb"]
RUN_WITHOUT_PREPARE.each { |path| require(path) }
Rails.application.reloader.to_prepare do
Dir["#{Rails.root}/lib/freedom_patches/*.rb"].each do |f| Dir["#{Rails.root}/lib/freedom_patches/*.rb"].each do |f|
next if RUN_WITHOUT_PREPARE.any? { |path| path == f }
require(f) require(f)
end end
end

View File

@@ -16,6 +16,7 @@ if GlobalSetting.skip_redis?
return return
end end
Rails.application.reloader.to_prepare do
reload_settings = lambda { reload_settings = lambda {
RailsMultisite::ConnectionManagement.safe_each_connection do RailsMultisite::ConnectionManagement.safe_each_connection do
begin begin
@@ -37,3 +38,4 @@ if !Rails.configuration.cache_classes
reload_settings.call reload_settings.call
end end
end end
end

View File

@@ -5,6 +5,7 @@
require 'i18n/backend/discourse_i18n' require 'i18n/backend/discourse_i18n'
require 'i18n/backend/fallback_locale_list' require 'i18n/backend/fallback_locale_list'
Rails.application.reloader.to_prepare do
I18n.backend = I18n::Backend::DiscourseI18n.new I18n.backend = I18n::Backend::DiscourseI18n.new
I18n.fallbacks = I18n::Backend::FallbackLocaleList.new I18n.fallbacks = I18n::Backend::FallbackLocaleList.new
I18n.config.missing_interpolation_argument_handler = proc { throw(:exception) } I18n.config.missing_interpolation_argument_handler = proc { throw(:exception) }
@@ -17,3 +18,4 @@ unless Rails.env.test?
ExtraLocalesController.clear_cache! ExtraLocalesController.clear_cache!
end end
end end
end

View File

@@ -1,12 +1,15 @@
# frozen_string_literal: true # frozen_string_literal: true
if GlobalSetting.skip_redis? if GlobalSetting.skip_redis?
Rails.application.reloader.to_prepare do
if Rails.logger.respond_to? :chained if Rails.logger.respond_to? :chained
Rails.logger = Rails.logger.chained.first Rails.logger = Rails.logger.chained.first
end end
end
return return
end end
Rails.application.reloader.to_prepare do
if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/) if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below" STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance" STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
@@ -146,3 +149,4 @@ Discourse.plugins.each do |plugin|
url: plugin.metadata.url url: plugin.metadata.url
} }
end end
end