From 33b3457a9f949dbfb0d85fbda3d549f0462be85b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 10:52:27 -0400 Subject: [PATCH 01/13] Use rails version 7.2.0.beta3 --- Gemfile | 5 +- Gemfile.lock | 142 ++++++++++++++++++++++++++------------------------- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/Gemfile b/Gemfile index de9bc45f320..40433667da4 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ ruby '>= 3.1.0' gem 'propshaft' gem 'puma', '~> 6.3' gem 'rack', '~> 2.2.7' -gem 'rails', '~> 7.1.1' +gem 'rails', '7.2.0.beta3' gem 'thor', '~> 1.2' gem 'dotenv' @@ -63,6 +63,7 @@ gem 'kaminari', '~> 1.2' gem 'link_header', '~> 0.0' gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock' gem 'mime-types', '~> 3.5.0', require: 'mime/types/columnar' +gem 'mutex_m' gem 'nokogiri', '~> 1.15' gem 'nsa' gem 'oj', '~> 3.14' @@ -141,7 +142,7 @@ group :test do gem 'selenium-webdriver' # Used to reset the database between system tests - gem 'database_cleaner-active_record' + gem 'database_cleaner-active_record', github: 'DatabaseCleaner/database_cleaner-active_record' # TODO: Release version? # Used to mock environment variables gem 'climate_control' diff --git a/Gemfile.lock b/Gemfile.lock index 1cf7f8d7696..17131ffe68e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,38 +7,40 @@ GIT hkdf (~> 0.2) jwt (~> 2.0) +GIT + remote: https://github.com/DatabaseCleaner/database_cleaner-active_record.git + revision: 79b08760d66369f43c40c49cc845a68ea9727e6e + specs: + database_cleaner-active_record (2.1.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3.4) - actionpack (= 7.1.3.4) - activesupport (= 7.1.3.4) + actioncable (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3.4) - actionpack (= 7.1.3.4) - activejob (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.3.4) - actionpack (= 7.1.3.4) - actionview (= 7.1.3.4) - activejob (= 7.1.3.4) - activesupport (= 7.1.3.4) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + activejob (= 7.2.0.beta3) + activerecord (= 7.2.0.beta3) + activestorage (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) + mail (>= 2.8.0) + actionmailer (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + actionview (= 7.2.0.beta3) + activejob (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.3.4) - actionview (= 7.1.3.4) - activesupport (= 7.1.3.4) + actionpack (7.2.0.beta3) + actionview (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -46,15 +48,16 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3.4) - actionpack (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) + useragent (~> 0.16) + actiontext (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + activerecord (= 7.2.0.beta3) + activestorage (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3.4) - activesupport (= 7.1.3.4) + actionview (7.2.0.beta3) + activesupport (= 7.2.0.beta3) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -64,31 +67,31 @@ GEM activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (7.1.3.4) - activesupport (= 7.1.3.4) + activejob (7.2.0.beta3) + activesupport (= 7.2.0.beta3) globalid (>= 0.3.6) - activemodel (7.1.3.4) - activesupport (= 7.1.3.4) - activerecord (7.1.3.4) - activemodel (= 7.1.3.4) - activesupport (= 7.1.3.4) + activemodel (7.2.0.beta3) + activesupport (= 7.2.0.beta3) + activerecord (7.2.0.beta3) + activemodel (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) timeout (>= 0.4.0) - activestorage (7.1.3.4) - actionpack (= 7.1.3.4) - activejob (= 7.1.3.4) - activerecord (= 7.1.3.4) - activesupport (= 7.1.3.4) + activestorage (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + activejob (= 7.2.0.beta3) + activerecord (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) marcel (~> 1.0) - activesupport (7.1.3.4) + activesupport (7.2.0.beta3) base64 bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) aes_key_wrap (1.1.0) @@ -180,9 +183,6 @@ GEM css_parser (1.17.1) addressable csv (3.3.0) - database_cleaner-active_record (2.2.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.4) debug (1.9.2) @@ -637,20 +637,20 @@ GEM rackup (1.0.0) rack (< 3) webrick - rails (7.1.3.4) - actioncable (= 7.1.3.4) - actionmailbox (= 7.1.3.4) - actionmailer (= 7.1.3.4) - actionpack (= 7.1.3.4) - actiontext (= 7.1.3.4) - actionview (= 7.1.3.4) - activejob (= 7.1.3.4) - activemodel (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) + rails (7.2.0.beta3) + actioncable (= 7.2.0.beta3) + actionmailbox (= 7.2.0.beta3) + actionmailer (= 7.2.0.beta3) + actionpack (= 7.2.0.beta3) + actiontext (= 7.2.0.beta3) + actionview (= 7.2.0.beta3) + activejob (= 7.2.0.beta3) + activemodel (= 7.2.0.beta3) + activerecord (= 7.2.0.beta3) + activestorage (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) bundler (>= 1.15.0) - railties (= 7.1.3.4) + railties (= 7.2.0.beta3) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -665,10 +665,10 @@ GEM rails-i18n (7.0.9) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - railties (7.1.3.4) - actionpack (= 7.1.3.4) - activesupport (= 7.1.3.4) - irb + railties (7.2.0.beta3) + actionpack (= 7.2.0.beta3) + activesupport (= 7.2.0.beta3) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -864,6 +864,7 @@ GEM unf_ext (0.0.9.1) unicode-display_width (2.5.0) uri (0.13.0) + useragent (0.16.10) validate_email (0.1.6) activemodel (>= 3.0) mail (>= 2.2.5) @@ -928,7 +929,7 @@ DEPENDENCIES concurrent-ruby connection_pool csv (~> 3.2) - database_cleaner-active_record + database_cleaner-active_record! debug (~> 1.8) devise (~> 4.9) devise-two-factor @@ -973,6 +974,7 @@ DEPENDENCIES md-paperclip-azure (~> 2.2) memory_profiler mime-types (~> 3.5.0) + mutex_m net-http (~> 0.4.0) net-ldap (~> 0.18) nokogiri (~> 1.15) @@ -1012,7 +1014,7 @@ DEPENDENCIES rack-attack (~> 6.6) rack-cors (~> 2.0) rack-test (~> 2.1) - rails (~> 7.1.1) + rails (= 7.2.0.beta3) rails-controller-testing (~> 1.0) rails-i18n (~> 7.0) rdf-normalize (~> 0.5) From 959c4e9224526aca6189652a44414e623ba7a726 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 10:53:19 -0400 Subject: [PATCH 02/13] Moved `migration_context` method to connection pool --- app/lib/admin/system_check/database_schema_check.rb | 2 +- lib/tasks/tests.rake | 2 +- spec/lib/admin/system_check/database_schema_check_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/lib/admin/system_check/database_schema_check.rb b/app/lib/admin/system_check/database_schema_check.rb index c2f01fd55b5..a3ef0613ea0 100644 --- a/app/lib/admin/system_check/database_schema_check.rb +++ b/app/lib/admin/system_check/database_schema_check.rb @@ -6,7 +6,7 @@ class Admin::SystemCheck::DatabaseSchemaCheck < Admin::SystemCheck::BaseCheck end def pass? - !ActiveRecord::Base.connection.migration_context.needs_migration? + !ActiveRecord::Base.connection_pool.migration_context.needs_migration? end def message diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index c8e4dc31cd7..e3b1a67f24b 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -11,7 +11,7 @@ namespace :tests do '3_3_0' => 2020_12_18_054746, }.each do |release, version| ActiveRecord::Tasks::DatabaseTasks - .migration_connection + .migration_connection_pool .migration_context .migrate(version) Rake::Task["tests:migrations:populate_v#{release}"] diff --git a/spec/lib/admin/system_check/database_schema_check_spec.rb b/spec/lib/admin/system_check/database_schema_check_spec.rb index db1dcb52fa4..19f68995f0c 100644 --- a/spec/lib/admin/system_check/database_schema_check_spec.rb +++ b/spec/lib/admin/system_check/database_schema_check_spec.rb @@ -13,7 +13,7 @@ describe Admin::SystemCheck::DatabaseSchemaCheck do context 'when database needs migration' do before do context = instance_double(ActiveRecord::MigrationContext, needs_migration?: true) - allow(ActiveRecord::Base.connection).to receive(:migration_context).and_return(context) + allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context) end it 'returns false' do @@ -24,7 +24,7 @@ describe Admin::SystemCheck::DatabaseSchemaCheck do context 'when database does not need migration' do before do context = instance_double(ActiveRecord::MigrationContext, needs_migration?: false) - allow(ActiveRecord::Base.connection).to receive(:migration_context).and_return(context) + allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context) end it 'returns true' do From 30a793e4630fb9dde299ef01f6ba11b20d7ba405 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 10:53:43 -0400 Subject: [PATCH 03/13] Update safe reblog insert for Rails 7.2 --- .../concerns/status/safe_reblog_insert.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/status/safe_reblog_insert.rb b/app/models/concerns/status/safe_reblog_insert.rb index 60ddb78e52c..0edbed0d664 100644 --- a/app/models/concerns/status/safe_reblog_insert.rb +++ b/app/models/concerns/status/safe_reblog_insert.rb @@ -15,7 +15,9 @@ module Status::SafeReblogInsert # # The code is kept similar to ActiveRecord::Persistence code and calls it # directly when we are not handling a reblog. - def _insert_record(values, returning) + # + # https://github.com/rails/rails/blob/7-2-stable/activerecord/lib/active_record/persistence.rb#L238-L263 + def _insert_record(connection, values, returning) return super unless values.is_a?(Hash) && values['reblog_of_id']&.value.present? primary_key = self.primary_key @@ -34,10 +36,15 @@ module Status::SafeReblogInsert # Instead, we use a custom builder when a reblog is happening: im = _compile_reblog_insert(values) - connection.insert(im, "#{self} Create", primary_key || false, primary_key_value, returning: returning).tap do |result| - # Since we are using SELECT instead of VALUES, a non-error `nil` return is possible. - # For our purposes, it's equivalent to a foreign key constraint violation - raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil? + with_connection do |_c| + connection.insert( + im, "#{self} Create", primary_key || false, primary_key_value, + returning: returning + ).tap do |result| + # Since we are using SELECT instead of VALUES, a non-error `nil` return is possible. + # For our purposes, it's equivalent to a foreign key constraint violation + raise ActiveRecord::InvalidForeignKey, "(reblog_of_id)=(#{values['reblog_of_id'].value}) is not present in table \"statuses\"" if result.nil? + end end end From d9edfaf111e531f36f37b0ed98ad24c8f5b1b477 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:04:02 -0400 Subject: [PATCH 04/13] New framework defaults --- .../new_framework_defaults_7_2.rb | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 config/initializers/new_framework_defaults_7_2.rb diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 00000000000..0344a6d022f --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. +# +# Example: +# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date +# +# This query used to return a `String`. +#++ +# Rails.application.config.active_record.postgresql_adapter_decode_dates = true + +### +# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are +# deploying to a memory constrained environment you may want to set this to `false`. +#++ +# Rails.application.config.yjit = true From cd6f72d40a484484b39525c99fad320b1aa7735c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:13:43 -0400 Subject: [PATCH 05/13] Generated development.rb update --- config/environments/development.rb | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index e4da60ac8e8..5fc5a6ed961 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,7 +16,7 @@ Rails.application.configure do # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true # Enable/disable caching. By default caching is disabled. @@ -26,9 +26,7 @@ Rails.application.configure do config.action_controller.enable_fragment_cache_logging = true config.cache_store = :redis_cache_store, REDIS_CACHE_PARAMS - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}", - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -37,11 +35,6 @@ Rails.application.configure do config.action_controller.forgery_protection_origin_check = ENV['DISABLE_FORGERY_REQUEST_PROTECTION'].nil? - ActiveSupport::Logger.new($stdout).tap do |logger| - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - # Generate random VAPID keys Webpush.generate_key.tap do |vapid_key| config.x.vapid_private_key = vapid_key.private_key @@ -53,6 +46,8 @@ Rails.application.configure do config.action_mailer.perform_caching = false + config.action_mailer.default_options = { from: 'notifications@localhost' } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -75,12 +70,7 @@ Rails.application.configure do # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true - - # Uncomment if you wish to allow Action Cable access from any origin. - # config.action_cable.disable_request_forgery_protection = true - - config.action_mailer.default_options = { from: 'notifications@localhost' } + config.action_view.annotate_rendered_view_with_filenames = true # If using a Heroku, Vagrant or generic remote development environment, # use letter_opener_web, accessible at /letter_opener. @@ -90,8 +80,11 @@ Rails.application.configure do # TODO: Remove once devise-two-factor data migration complete config.x.otp_secret = ENV.fetch('OTP_SECRET', '1fc2b87989afa6351912abeebe31ffc5c476ead9bf8b3d74cbc4a302c7b69a45b40b1bbef3506ddad73e942e15ed5ca4b402bf9a66423626051104f4b5f05109') - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end Redis.raise_deprecations = true From 9ec81a663e59d4afe2674d09856852d76ae5a323 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:41:42 -0400 Subject: [PATCH 06/13] Generated env updates --- config/environments/production.rb | 47 ++++++++++++++----------------- config/environments/test.rb | 18 ++++++------ 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index b42f78b14ea..7e164aa3834 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -15,22 +15,18 @@ Rails.application.configure do config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true - config.action_controller.asset_host = ENV['CDN_HOST'] if ENV['CDN_HOST'].present? # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true - # Compress CSS using a preprocessor. - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + # config.public_file_server.enabled = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.asset_host = "http://assets.example.com" + config.asset_host = ENV['CDN_HOST'] if ENV['CDN_HOST'].present? # Specifies the header that your server uses for sending files. config.action_dispatch.x_sendfile_header = ENV['SENDFILE_HEADER'] if ENV['SENDFILE_HEADER'].present? @@ -40,27 +36,37 @@ Rails.application.configure do # Allow to specify public IP of reverse proxy if it's needed config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split(/(?:\s*,\s*|\s+)/).map { |item| IPAddr.new(item) } if ENV['TRUSTED_PROXY_IP'].present? + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true + # Skip http-to-https redirect for the default health check endpoint. config.ssl_options = { redirect: { exclude: ->(request) { request.path.start_with?('/health') || request.headers['Host'].end_with?('.onion') || request.headers['Host'].end_with?('.i2p') }, }, } - # Info include generic and useful information about system operation, but avoids logging too much - # information to avoid inadvertent exposure of personally identifiable information (PII). If you - # want to log everything, set the level to "debug". - config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. config.log_tags = [:request_id] + # "info" includes generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + # Use a different cache store in production. config.cache_store = :redis_cache_store, REDIS_CACHE_PARAMS # Use a real queuing backend for Active Job (and separate queues per environment). - # config.active_job.queue_adapter = :resque + # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "mastodon_production" config.action_mailer.perform_caching = false @@ -70,9 +76,8 @@ Rails.application.configure do # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # English when a translation cannot be found). - # This setting would typically be `true` to use the `I18n.default_locale`. - # Some locales are missing translation entries and would have errors: + # the I18n.default_locale when a translation cannot be found). + # Default value is `true`, but some locales have missing data and would have errors # https://github.com/mastodon/mastodon/pull/24727 config.i18n.fallbacks = [:en] @@ -89,18 +94,8 @@ Rails.application.configure do { key: controller.signature_key_id } if controller.respond_to?(:signed_request?) && controller.signed_request? end - # Use a different logger for distributed setups. - # require "syslog/logger" - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") - - # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new($stdout) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - config.action_mailer.perform_caching = false # E-mails diff --git a/config/environments/test.rb b/config/environments/test.rb index 716bf8d31f1..173d09fc405 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -19,14 +19,15 @@ Rails.application.configure do # loading is working properly before deploying your code. config.eager_load = ENV['CI'].present? - config.assets_digest = false + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false - config.cache_store = :memory_store + config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. + # Render exception templates for rescuable exceptions and raise for other exceptions. config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. @@ -34,13 +35,15 @@ Rails.application.configure do config.action_mailer.perform_caching = false - config.action_mailer.default_options = { from: 'notifications@localhost' } - # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: 'www.example.com' } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -58,7 +61,6 @@ Rails.application.configure do # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise - config.i18n.default_locale = :en config.i18n.fallbacks = true # Tell Active Support which deprecation messages to disallow. @@ -70,7 +72,7 @@ Rails.application.configure do # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true end From 85a761722c125aceaac062f5c4ea66ede0abc653 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:42:07 -0400 Subject: [PATCH 07/13] Use 7.2 defaults --- config/application.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 3c62a492289..36c58a33540 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,10 +61,7 @@ Bundler.require(:pam_authentication) if ENV['PAM_ENABLED'] == 'true' module Mastodon class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.1 - - # Explicitly set the cache format version to align with Rails version - config.active_support.cache_format_version = 7.1 + config.load_defaults 7.2 # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. From aec78a72529c618ebc10181a9b5ae59da728765e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:51:25 -0400 Subject: [PATCH 08/13] Restore default mail from --- config/environments/test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/environments/test.rb b/config/environments/test.rb index 173d09fc405..49203a33a6a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -35,6 +35,8 @@ Rails.application.configure do config.action_mailer.perform_caching = false + config.action_mailer.default_options = { from: 'notifications@localhost' } + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. From a060a6b8bfe3f212b418fc7067ba60ed565bca78 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:52:33 -0400 Subject: [PATCH 09/13] cache store is memory store in test env --- config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 49203a33a6a..a4612129c34 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -25,7 +25,7 @@ Rails.application.configure do # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - config.cache_store = :null_store + config.cache_store = :memory_store # Render exception templates for rescuable exceptions and raise for other exceptions. config.action_dispatch.show_exceptions = :rescuable From 229c800971d889cf9b3c84a5e2ed39f8b571e943 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 6 Jun 2024 11:54:46 -0400 Subject: [PATCH 10/13] format --- config/environments/development.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 5fc5a6ed961..af5be44b4be 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -26,7 +26,9 @@ Rails.application.configure do config.action_controller.enable_fragment_cache_logging = true config.cache_store = :redis_cache_store, REDIS_CACHE_PARAMS - config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}", + } else config.action_controller.perform_caching = false From f1c47e5f3472692d5eec9f6e55f9c5650b4be6fe Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 16 Jul 2024 09:52:50 -0400 Subject: [PATCH 11/13] Use test-prof 1.4.0.rc1 --- Gemfile | 2 +- Gemfile.lock | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 40433667da4..15432d1b739 100644 --- a/Gemfile +++ b/Gemfile @@ -209,7 +209,7 @@ group :development, :test do gem 'memory_profiler', require: false gem 'ruby-prof', require: false gem 'stackprof', require: false - gem 'test-prof' + gem 'test-prof', github: 'test-prof/test-prof' # RSpec runner for rails gem 'rspec-rails', '~> 6.0' diff --git a/Gemfile.lock b/Gemfile.lock index 17131ffe68e..8cc66cdd530 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,6 +15,12 @@ GIT activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) +GIT + remote: https://github.com/test-prof/test-prof.git + revision: 0259a76d2242a63d01556100ee208d29eaf1429c + specs: + test-prof (1.4.0.rc.1) + GEM remote: https://rubygems.org/ specs: @@ -834,7 +840,6 @@ GEM unicode-display_width (>= 1.1.1, < 3) terrapin (1.0.1) climate_control - test-prof (1.3.3.1) thor (1.3.1) tilt (2.3.0) timeout (0.4.1) @@ -1049,7 +1054,7 @@ DEPENDENCIES stackprof stoplight (~> 4.1) strong_migrations - test-prof + test-prof! thor (~> 1.2) tty-prompt (~> 0.23) twitter-text (~> 3.1.0) From 44c9e2cc0489a883fea121ff7bd817fdfe2f26e7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 25 Jul 2024 13:14:24 -0400 Subject: [PATCH 12/13] Update test-prof to version 1.4.0.rc.3 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8cc66cdd530..9df2b8e3188 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,9 +17,9 @@ GIT GIT remote: https://github.com/test-prof/test-prof.git - revision: 0259a76d2242a63d01556100ee208d29eaf1429c + revision: 1eebcbbb6c192fe5e79046c6bd692731b3925148 specs: - test-prof (1.4.0.rc.1) + test-prof (1.4.0.rc.3) GEM remote: https://rubygems.org/ From 0b274bd554a55d2c6714bc18321c955bb637b15e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 26 Jul 2024 14:10:15 -0400 Subject: [PATCH 13/13] Update test-prof to version 1.4.0.rc.4 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9df2b8e3188..18b0af28ce1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,9 +17,9 @@ GIT GIT remote: https://github.com/test-prof/test-prof.git - revision: 1eebcbbb6c192fe5e79046c6bd692731b3925148 + revision: 065ca2465118769a1a809dac66ff57f07562691d specs: - test-prof (1.4.0.rc.3) + test-prof (1.4.0.rc.4) GEM remote: https://rubygems.org/