DEV: Upgrade Rails to version 7.1

---------

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
Loïc Guitaut
2024-06-20 10:33:01 +02:00
committed by Loïc Guitaut
parent 706e074e6c
commit ce00f83173
48 changed files with 495 additions and 258 deletions

View File

@ -954,14 +954,7 @@ module Discourse
def self.warn(message, env = nil)
append = env ? (+" ") << env.map { |k, v| "#{k}: #{v}" }.join(" ") : ""
if !(Logster::Logger === Rails.logger)
Rails.logger.warn("#{message}#{append}")
return
end
loggers = [Rails.logger]
loggers.concat(Rails.logger.chained) if Rails.logger.chained
loggers = Rails.logger.broadcasts
logster_env = env
if old_env = Thread.current[Logster::Logger::LOGSTER_ENV]
@ -1116,16 +1109,7 @@ module Discourse
end
end
schema_cache = ActiveRecord::Base.connection.schema_cache
RailsMultisite::ConnectionManagement.safe_each_connection do
# load up schema cache for all multisite assuming all dbs have
# an identical schema
dup_cache = schema_cache.dup
# this line is not really needed, but just in case the
# underlying implementation changes lets give it a shot
dup_cache.connection = nil
ActiveRecord::Base.connection.schema_cache = dup_cache
I18n.t(:posts)
# this will force Cppjieba to preload if any site has it

View File

@ -0,0 +1,58 @@
# frozen_string_literal: true
# TODO: Drop this patch when upgrading to Rails 7.2
#
# Here we use the code from Rails 7.2 because the code from Rails 7.1 has a
# nasty bug that happens when there is more than one tagged logger in the
# broadcast logger.
# The Rails 7.1 implementation calls `#call_app` as many times as there are
# tagged loggers, which leads to all sort of strange behaviors.
module RailsRackLoggerFromRails7_2
extend ActiveSupport::Concern
def call(env)
request = ActionDispatch::Request.new(env)
env["rails.rack_logger_tag_count"] = if logger.respond_to?(:push_tags)
logger.push_tags(*compute_tags(request)).size
else
0
end
call_app(request, env)
end
private
def call_app(request, env) # :doc:
logger_tag_pop_count = env["rails.rack_logger_tag_count"]
instrumenter = ActiveSupport::Notifications.instrumenter
handle = instrumenter.build_handle("request.action_dispatch", { request: request })
handle.start
logger.info { started_request_message(request) }
status, headers, body = response = @app.call(env)
body =
::Rack::BodyProxy.new(body) { finish_request_instrumentation(handle, logger_tag_pop_count) }
if response.frozen?
[status, headers, body]
else
response[2] = body
response
end
rescue Exception
finish_request_instrumentation(handle, logger_tag_pop_count)
raise
end
def finish_request_instrumentation(handle, logger_tag_pop_count)
handle.finish
if logger.respond_to?(:pop_tags) && logger_tag_pop_count > 0
logger.pop_tags(logger_tag_pop_count)
end
ActiveSupport::LogSubscriber.flush_all!
end
end
Rails::Rack::Logger.prepend(RailsRackLoggerFromRails7_2)

View File

@ -53,10 +53,10 @@ module Hijack
# this trick avoids double render, also avoids any litter that the controller hooks
# place on the response
instance = controller_class.new
response = ActionDispatch::Response.new
instance.response = response
response = ActionDispatch::Response.new.tap { _1.request = request_copy }
instance.set_response!(response)
instance.set_request!(request_copy)
instance.request = request_copy
original_headers&.each { |k, v| instance.response.headers[k] = v }
view_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)

View File

@ -34,7 +34,7 @@ module Middleware
if exception
begin
fake_controller = ApplicationController.new
fake_controller.response = response
fake_controller.set_response!(response)
fake_controller.request = request = ActionDispatch::Request.new(env)
# We can not re-dispatch bad mime types

View File

@ -274,7 +274,7 @@ module SiteSettingExtension
end
def description(setting)
I18n.t("site_settings.#{setting}", base_path: Discourse.base_path)
I18n.t("site_settings.#{setting}", base_path: Discourse.base_path, default: "")
end
def keywords(setting)