OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Introduce registry to ensure we eager load all of them
Oliver Güntherd0ef27dcb620
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rbindex 07841657eea..e9dfc358734 100644--- a/app/controllers/enumerations_controller.rb+++ b/app/controllers/enumerations_controller.rb@@ -115,6 +115,6 @@ class EnumerationsController < ApplicationController### Find an enumeration class with the given namedef enumeration_class(type)- Enumeration.subclasses.detect { |cls| cls.name == type }+ Enumeration.registered_subclasses.detect { |cls| cls.name == type }endenddiff --git a/app/models/concerns/subclass_registry.rb b/app/models/concerns/subclass_registry.rbnew file mode 100644index 00000000000..37159680d38--- /dev/null+++ b/app/models/concerns/subclass_registry.rb@@ -0,0 +1,45 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module SubclassRegistry+ extend ActiveSupport::Concern++ included do+ class_attribute :registered_subclasses, default: []+ end++ class_methods do+ def register_subclass(subclass)+ raise ArgumentError, "#{subclass} needs to inherit from #{self}" unless subclass < self++ unless registered_subclasses.include?(subclass)+ registered_subclasses << subclass+ end+ end+ end+enddiff --git a/app/models/enumeration.rb b/app/models/enumeration.rbindex 2aba1f53f90..da80df87146 100644--- a/app/models/enumeration.rb+++ b/app/models/enumeration.rb@@ -27,6 +27,8 @@#++class Enumeration < ApplicationRecord+ include SubclassRegistry+default_scope { order("#{Enumeration.table_name}.position ASC") }belongs_to :project, optional: truediff --git a/config/initializers/sti_eager_load.rb b/config/initializers/sti_eager_load.rbnew file mode 100644index 00000000000..686afe5db85--- /dev/null+++ b/config/initializers/sti_eager_load.rb@@ -0,0 +1,31 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++Rails.application.config.to_prepare do+ Enumeration.register_subclass(IssuePriority)+enddiff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rbindex 47a1adb79e6..c495985b10e 100644--- a/modules/costs/lib/costs/engine.rb+++ b/modules/costs/lib/costs/engine.rb@@ -282,8 +282,8 @@ module Costsendconfig.to_prepare do+ Enumeration.register_subclass(TimeEntryActivity)OpenProject::ProjectLatestActivity.register on: "TimeEntry"-Costs::Patches::MembersPatch.mixin!##diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rbindex 810328b43dd..c8d6e1e85d5 100644--- a/modules/documents/lib/open_project/documents/engine.rb+++ b/modules/documents/lib/open_project/documents/engine.rb@@ -77,5 +77,9 @@ module OpenProject::Documents# Add documents to allowed search paramsadditional_permitted_attributes search: %i(documents)++ config.to_prepare do+ Enumeration.register_subclass(DocumentCategory)+ endendend