Actions
Feature #16646
closedAllow Foreman controllers to be extended to include fields from external plugins
Difficulty:
Triaged:
Bugzilla link:
Pull request:
Description
Problem:
If an external plugin, such as Katello, uses database fields in a view that Foreman prepares in a Foreman controller, additional database queries are run from the view layer as the fields or related tables are requested. In index views, this issue causes N+1 query warnings as the view iterates over each object.
Proposed solution:
Allow index actions to be extended per-controller to use a private class method which provide additional fields to pass to the ActiveRecord::Relation#includes method.
Example:
class HostsController
class << self do
def index_fields
@index_fields ||= {}
end
def include_index_field(field_hash)
index_fields.merge!(field_hash)
end
end
def index
@hosts = Host.includes(self.class.index_fields)
end
end
Actions