Feature #16646

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

Added by Andrew Kofink about 1 year ago. Updated about 1 year ago.

Status:Closed
Priority:Normal
Assigned To:Shimon Shtein
Category:Plugins-Engines
Target version:Team Ivan Iteration 5
Difficulty: Bugzilla link:1297683
Found in release: Pull request:https://github.com/theforeman/foreman/pull/3887
Story points-
Velocity based estimate-
Release1.14.0Release relationshipAuto

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

Related to Katello - Bug #16010: "Error: Request Timeout" from hammer when asked to show >... Closed 08/08/2016
Related to Discovery - Refactor #17085: Make use of index scope DSL New 10/25/2016

Associated revisions

Revision 87f8f03e
Added by Shimon Shtein about 1 year ago

Fixes #16646 - Add ability to plugins to modify index scope

History

#1 Updated by Andrew Kofink about 1 year ago

  • Related to Bug #16010: "Error: Request Timeout" from hammer when asked to show >400 content hosts added

#2 Updated by Dominic Cleal about 1 year ago

  • Category set to Plugins-Engines
  • Status changed from New to Assigned

#3 Updated by Shimon Shtein about 1 year ago

  • Target version set to Team Ivan Iteration 3

#4 Updated by The Foreman Bot about 1 year ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3887 added

#5 Updated by Ivan Necas about 1 year ago

  • Target version changed from Team Ivan Iteration 3 to Team Ivan Iteration 4

#6 Updated by Ivan Necas about 1 year ago

  • Target version changed from Team Ivan Iteration 4 to Team Ivan Iteration 5

#7 Updated by Lukas Zapletal about 1 year ago

#8 Updated by Shimon Shtein about 1 year ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#9 Updated by Dominic Cleal about 1 year ago

  • Release set to 1.14.0

Also available in: Atom PDF