Merge pull request #10275 from opf/fix/prevent-autoloading-constants-during-initialization

Stop autoloading constants during initialization
pull/10290/head
ulferts 3 years ago committed by GitHub
commit cade7fdaab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/models/activities/fetcher.rb
  2. 15
      config/constants/open_project/activity.rb
  3. 2
      config/constants/project_activity.rb
  4. 46
      config/initializers/activity.rb
  5. 9
      config/initializers/delayed_job_config.rb
  6. 14
      config/initializers/i18n.rb
  7. 2
      config/initializers/permissions.rb
  8. 8
      config/initializers/register_mail_interceptors.rb
  9. 2
      lib/plugins/acts_as_journalized/lib/acts/journalized/options.rb
  10. 8
      modules/budgets/lib/budgets/engine.rb
  11. 4
      modules/costs/lib/costs/engine.rb
  12. 4
      modules/meeting/lib/open_project/meeting/engine.rb

@ -48,7 +48,7 @@ module Activities
# Returns an array of available event types
def event_types
@event_types ||= begin
@event_types ||=
if @project
OpenProject::Activity.available_event_types.select do |o|
@project.self_and_descendants.detect do |_p|
@ -60,9 +60,8 @@ module Activities
end
end
else
OpenProject::Activity.available_event_types
OpenProject::Activity.available_event_types.to_a
end
end
end
# Returns an array of events for the given date range
@ -92,7 +91,7 @@ module Activities
# Resets the scope to the default scope
def default_scope!
@scope = OpenProject::Activity.default_event_types
@scope = OpenProject::Activity.default_event_types.to_a
end
def events_from_providers(from, to, limit)

@ -32,15 +32,15 @@ module OpenProject
module Activity
class << self
def available_event_types
@available_event_types ||= []
@available_event_types ||= Set.new
end
def default_event_types
@default_event_types ||= []
@default_event_types ||= Set.new
end
def providers
@providers ||= Hash.new { |h, k| h[k] = [] }
@providers ||= Hash.new { |h, k| h[k] = Set.new }
end
def map(&_block)
@ -52,12 +52,11 @@ module OpenProject
options.assert_valid_keys(:class_name, :default)
event_type = event_type.to_s
providers = options[:class_name] || event_type.classify
providers = ([] << providers) unless providers.is_a?(Array)
available_event_types << event_type
default_event_types << event_type unless options[:default] == false
available_event_types << event_type unless available_event_types.include?(event_type)
default_event_types << event_type unless default_event_types.include?(event_type) || options[:default] == false
self.providers[event_type] += providers
providers = options[:class_name] || event_type.classify
self.providers[event_type] += Array(providers)
end
end
end

@ -32,7 +32,7 @@ module Constants
module ProjectActivity
class << self
def register(on:, attribute:, chain: [])
@registered ||= []
@registered ||= Set.new
@registered << { on: on,
chain: chain,

@ -28,31 +28,33 @@
# See COPYRIGHT and LICENSE files for more details.
#++
OpenProject::Activity.map do |activity|
activity.register :work_packages, class_name: '::Activities::WorkPackageActivityProvider'
activity.register :changesets, class_name: 'Activities::ChangesetActivityProvider'
activity.register :news, class_name: 'Activities::NewsActivityProvider',
default: false
activity.register :wiki_edits, class_name: 'Activities::WikiContentActivityProvider',
Rails.application.reloader.to_prepare do
OpenProject::Activity.map do |activity|
activity.register :work_packages, class_name: '::Activities::WorkPackageActivityProvider'
activity.register :changesets, class_name: 'Activities::ChangesetActivityProvider'
activity.register :news, class_name: 'Activities::NewsActivityProvider',
default: false
activity.register :wiki_edits, class_name: 'Activities::WikiContentActivityProvider',
default: false
activity.register :messages, class_name: 'Activities::MessageActivityProvider',
default: false
activity.register :messages, class_name: 'Activities::MessageActivityProvider',
default: false
end
end
Project.register_latest_project_activity on: 'WorkPackage',
attribute: :updated_at
Project.register_latest_project_activity on: 'WorkPackage',
attribute: :updated_at
Project.register_latest_project_activity on: 'News',
attribute: :updated_at
Project.register_latest_project_activity on: 'News',
attribute: :updated_at
Project.register_latest_project_activity on: 'Changeset',
chain: 'Repository',
attribute: :committed_on
Project.register_latest_project_activity on: 'Changeset',
chain: 'Repository',
attribute: :committed_on
Project.register_latest_project_activity on: 'WikiContent',
chain: %w(Wiki WikiPage),
attribute: :updated_at
Project.register_latest_project_activity on: 'WikiContent',
chain: %w(Wiki WikiPage),
attribute: :updated_at
Project.register_latest_project_activity on: 'Message',
chain: 'Forum',
attribute: :updated_at
Project.register_latest_project_activity on: 'Message',
chain: 'Forum',
attribute: :updated_at
end

@ -34,9 +34,12 @@ Delayed::Worker.logger = nil
# By default bypass worker queue and execute asynchronous tasks at once
Delayed::Worker.delay_jobs = true
# Set default priority (lower = higher priority)
# Example ordering, see ApplicationJob.priority_number
Delayed::Worker.default_priority = ::ApplicationJob.priority_number(:default)
# Prevent loading ApplicationJob during initialization
Rails.application.reloader.to_prepare do
# Set default priority (lower = higher priority)
# Example ordering, see ApplicationJob.priority_number
Delayed::Worker.default_priority = ::ApplicationJob.priority_number(:default)
end
# Do not retry jobs from delayed_job
# instead use 'retry_on' activejob functionality

@ -6,10 +6,12 @@ I18n::Backend::Simple.include OpenProject::Translations::PluralizationBackend
# Adds fallback to default locale for untranslated strings
I18n::Backend::Simple.include I18n::Backend::Fallbacks
# As we enabled +config.i18n.fallbacks+, Rails will fall back
# to the default locale.
# When other locales are available, fall back to them.
if Setting.table_exists? # don't want to prevent migrations
defaults = Set.new I18n.fallbacks.defaults + Setting.available_languages.map(&:to_sym)
I18n.fallbacks.defaults = defaults
Rails.application.reloader.to_prepare do
# As we enabled +config.i18n.fallbacks+, Rails will fall back
# to the default locale.
# When other locales are available, fall back to them.
if Setting.table_exists? # don't want to prevent migrations
defaults = Set.new I18n.fallbacks.defaults + Setting.available_languages.map(&:to_sym)
I18n.fallbacks.defaults = defaults
end
end

@ -38,7 +38,7 @@ OpenProject::AccessControl.map do |map|
global: true,
contract_actions: { projects: %i[create] }
map.permission Backup.permission,
map.permission :create_backup,
{ backups: %i[index] },
require: :loggedin,
global: true,

@ -31,6 +31,8 @@
# Register interceptors defined in app/mailers/user_mailer.rb
# Do this here, so they aren't registered multiple times due to reloading in development mode.
ApplicationMailer.register_interceptor(DefaultHeadersInterceptor)
# following needs to be the last interceptor
ApplicationMailer.register_interceptor(DoNotSendMailsWithoutReceiverInterceptor)
Rails.application.config.action_mailer.interceptors = [
"DefaultHeadersInterceptor",
# following needs to be the last interceptor
"DoNotSendMailsWithoutReceiverInterceptor"
]

@ -103,7 +103,7 @@ module Acts::Journalized
def options_with_defaults(options)
{
class_name: Journal.name,
class_name: 'Journal',
dependent: :destroy,
foreign_key: :journable_id,
timestamp: :updated_at,

@ -42,17 +42,15 @@ module Budgets
mount ::API::V3::Budgets::BudgetsByProjectAPI
end
initializer 'budgets.register_latest_project_activity' do
Project.register_latest_project_activity on: 'Budget',
attribute: :updated_at
end
initializer 'budgets.register_hooks' do
# TODO: avoid hooks as this is part of the core now
require 'budgets/hooks/work_package_hook'
end
config.to_prepare do
Project.register_latest_project_activity on: 'Budget',
attribute: :updated_at
# Add to the budget to the costs group
::Type.add_default_mapping(:costs, :budget)

@ -248,12 +248,10 @@ module Costs
writable: false
end
initializer 'costs.register_latest_project_activity' do
config.to_prepare do
Project.register_latest_project_activity on: 'TimeEntry',
attribute: :updated_at
end
config.to_prepare do
Costs::Patches::MembersPatch.mixin!
##

@ -80,12 +80,10 @@ module OpenProject::Meeting
mount ::API::V3::Meetings::MeetingContentsAPI
end
initializer 'meeting.register_latest_project_activity' do
config.to_prepare do
Project.register_latest_project_activity on: 'Meeting',
attribute: :updated_at
end
config.to_prepare do
PermittedParams.permit(:search, :meetings)
end

Loading…
Cancel
Save