diff options
author | Starfall <us@starfall.systems> | 2023-04-14 19:22:47 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2023-04-14 19:22:47 -0500 |
commit | 4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (patch) | |
tree | 6811b845bb7f4966b10dcefa3dea404246f161c7 /config/initializers | |
parent | 65c1e53a32cabcdbb7bca57002bb0f6acdebe07e (diff) | |
parent | bed63f6dae0879ac840066b031229e0d139089cd (diff) |
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/0_duplicate_migrations.rb | 24 | ||||
-rw-r--r-- | config/initializers/chewy.rb | 2 | ||||
-rw-r--r-- | config/initializers/inflections.rb | 1 | ||||
-rw-r--r-- | config/initializers/paperclip.rb | 7 | ||||
-rw-r--r-- | config/initializers/rack_attack.rb | 10 | ||||
-rw-r--r-- | config/initializers/redis.rb | 1 | ||||
-rw-r--r-- | config/initializers/simple_form.rb | 1 |
7 files changed, 34 insertions, 12 deletions
diff --git a/config/initializers/0_duplicate_migrations.rb b/config/initializers/0_duplicate_migrations.rb index 6c45e4bd2..1b8b59025 100644 --- a/config/initializers/0_duplicate_migrations.rb +++ b/config/initializers/0_duplicate_migrations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Some migrations have been present in glitch-soc for a long time and have then # been merged in upstream Mastodon, under a different version number. # @@ -12,24 +14,26 @@ # we decided monkey-patching Rails' Migrator to completely ignore the duplicate, # keeping only the one that has run, or an arbitrary one. -ALLOWED_DUPLICATES = [20180410220657, 20180831171112].freeze +ALLOWED_DUPLICATES = [2018_04_10_220657, 2018_08_31_171112].freeze module ActiveRecord class Migrator def self.new(direction, migrations, schema_migration, target_version = nil) migrated = Set.new(Base.connection.migration_context.get_all_versions) - migrations.group_by(&:name).each do |name, duplicates| - if duplicates.length > 1 && duplicates.all? { |m| ALLOWED_DUPLICATES.include?(m.version) } - # We have a set of allowed duplicates. Keep the migrated one, if any. - non_migrated = duplicates.reject { |m| migrated.include?(m.version.to_i) } + migrations.group_by(&:name).each do |_name, duplicates| + next unless duplicates.length > 1 && duplicates.all? { |m| ALLOWED_DUPLICATES.include?(m.version) } + + # We have a set of allowed duplicates. Keep the migrated one, if any. + non_migrated = duplicates.reject { |m| migrated.include?(m.version.to_i) } - if duplicates.length == non_migrated.length || non_migrated.length == 0 + migrations = begin + if duplicates.length == non_migrated.length || non_migrated.empty? # There weren't any migrated one, so we have to pick one “canonical” migration - migrations = migrations - duplicates[1..-1] + migrations - duplicates[1..] else # Just reject every duplicate which hasn't been migrated yet - migrations = migrations - non_migrated + migrations - non_migrated end end end @@ -43,10 +47,10 @@ module ActiveRecord # A set of duplicated migrations is considered migrated if at least one of # them is migrated. migrated = get_all_versions - migrations.group_by(&:name).each do |name, duplicates| + migrations.group_by(&:name).each do |_name, duplicates| return true unless duplicates.any? { |m| migrated.include?(m.version.to_i) } end - return false + false end end end diff --git a/config/initializers/chewy.rb b/config/initializers/chewy.rb index 752fc3c6d..daf4a5f32 100644 --- a/config/initializers/chewy.rb +++ b/config/initializers/chewy.rb @@ -19,7 +19,7 @@ Chewy.settings = { # cycle, which takes care of checking if Elasticsearch is enabled # or not. However, mind that for the Rails console, the :urgent # strategy is set automatically with no way to override it. -Chewy.root_strategy = :mastodon +Chewy.root_strategy = :bypass_with_warning if Rails.env.production? Chewy.request_strategy = :mastodon Chewy.use_after_commit_callbacks = false diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index a361cb0ec..95f0b5788 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -26,6 +26,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'URL' inflect.acronym 'ASCII' inflect.acronym 'DeepL' + inflect.acronym 'DSL' inflect.singular 'data', 'data' end diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index a2285427c..bd37f6709 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -90,6 +90,12 @@ if ENV['S3_ENABLED'] == 'true' ) end + if ENV.has_key?('S3_STORAGE_CLASS') + Paperclip::Attachment.default_options[:s3_headers].merge!( + 'X-Amz-Storage-Class' => ENV['S3_STORAGE_CLASS'] + ) + end + # Some S3-compatible providers might not actually be compatible with some APIs # used by kt-paperclip, see https://github.com/mastodon/mastodon/issues/16822 if ENV['S3_FORCE_SINGLE_REQUEST'] == 'true' @@ -124,6 +130,7 @@ elsif ENV['SWIFT_ENABLED'] == 'true' openstack_domain_name: ENV.fetch('SWIFT_DOMAIN_NAME') { 'default' }, openstack_region: ENV['SWIFT_REGION'], openstack_cache_ttl: ENV.fetch('SWIFT_CACHE_TTL') { 60 }, + openstack_temp_url_key: ENV['SWIFT_TEMP_URL_KEY'], }, fog_file: { 'Cache-Control' => 'public, max-age=315576000, immutable' }, diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 72ef7ba80..3857e3055 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -33,6 +33,10 @@ class Rack::Attack authenticated_token&.resource_owner_id end + def authenticated_token_id + authenticated_token&.id + end + def unauthenticated? !authenticated_user_id end @@ -62,10 +66,14 @@ class Rack::Attack IpBlock.blocked?(req.remote_ip) end - throttle('throttle_authenticated_api', limit: 300, period: 5.minutes) do |req| + throttle('throttle_authenticated_api', limit: 1_500, period: 5.minutes) do |req| req.authenticated_user_id if req.api_request? end + throttle('throttle_per_token_api', limit: 300, period: 5.minutes) do |req| + req.authenticated_token_id if req.api_request? + end + throttle('throttle_unauthenticated_api', limit: 300, period: 5.minutes) do |req| req.throttleable_remote_ip if req.api_request? && req.unauthenticated? end diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb new file mode 100644 index 000000000..f2bbd1e45 --- /dev/null +++ b/config/initializers/redis.rb @@ -0,0 +1 @@ +Redis.sadd_returns_boolean = false diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 5e4763b7f..2de22a945 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -11,6 +11,7 @@ end module GlitchOnlyComponent def glitch_only(_wrapper_options = nil) return unless options[:glitch_only] + options[:label_text] = ->(raw_label_text, _required_label_text, _label_present) { safe_join([raw_label_text, ' ', content_tag(:span, I18n.t('simple_form.glitch_only'), class: 'glitch_only')]) } nil end |