Project

General

Profile

Actions

Feature #16646

closed

Allow Foreman controllers to be extended to include fields from external plugins

Added by Andrew Kofink about 8 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Plugin integration
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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

Related issues 2 (1 open1 closed)

Related to Katello - Bug #16010: "Error: Request Timeout" from hammer when asked to show >400 content hostsClosedAndrew Kofink08/08/2016Actions
Related to Discovery - Refactor #17085: Make use of index scope DSLNew10/25/2016Actions
Actions

Also available in: Atom PDF