Skip to content

Commit

Permalink
Refs #36715 - fix loaders; work around weird method arg behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Sep 8, 2023
1 parent b2c0037 commit a64b7de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/models/host/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ def facts_hash
returns Hash, desc: 'A hash of facts, keys are fact names, values are fact values'
example '@host.facts_with_names([\'dmi::memory::size\', \'net::interface::eth0\']) # => { "dmi::memory::size"=>"16 GB", "net::interface::eth0"=>"00:50:56:8a:5c:3c" }', desc: 'Getting specific facts'
end
def facts_with_names(names_query = [])
filtered_names = Set.new(names_query)
def facts_with_names(names_query = [], *args)
filtered_names = Set.new([names_query, *args].flatten.compact)
result = {}
names = {} # { fact_name_id => fact_name_name}
names = {} # { fact_name_id => fact_name_name }
fact_names.each do |fact_name|
next unless filtered_names.empty? || filtered_names.include?(fact_name.name)
names[fact_name.id] = fact_name.name
end
f_values = {} # { fact_name_id => fact_value_value}
f_values = {} # { fact_name_id => fact_value_value }
fact_values.each do |fact_value|
next unless names[fact_value.fact_name_id]
f_values[fact_value.fact_name_id] = fact_value.value
Expand Down
6 changes: 4 additions & 2 deletions app/services/foreman/renderer/scope/macros/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ module Loaders
end
end

def load_hosts_with_facts(fact_names:, search:, permission:, batch: 1_000, includes: nil, limit: nil, select: nil, joins: nil, where: nil, preload: nil)
def load_hosts_with_facts(search:, batch: 1_000, includes: nil, limit: nil, select: nil, joins: nil, where: nil, preload: nil)
incl = [:fact_values, :fact_names] + (includes || [])
load_hosts(search: search, permission: permission, batch: batch, includes: incl, limit: limit, select: select, joins: joins, where: where, preload: preload)
load_resource(klass: Host, permission: :view_hosts, search: search, batch: batch, includes: incl, limit: limit, select: select, joins: joins, where: where, preload: preload)
end

LOADERS << [:load_hosts_with_facts]

private

# returns a batched relation, use either
Expand Down

0 comments on commit a64b7de

Please sign in to comment.