Skip to content

Commit

Permalink
Merge pull request #85 from h0tw1r3/optimize-puppetdb-query
Browse files Browse the repository at this point in the history
optimize puppetdb query
  • Loading branch information
zilchms authored Jan 29, 2024
2 parents 387b071 + 3c9cc1a commit f61cd0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/puppet-ghostbuster/puppetdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ def client

def self.classes
@@classes ||= client.request('',
'resources[title] { type = "Class" and nodes { deactivated is null } }').data.map do |r|
'resources[title] { type = "Class" and nodes { deactivated is null } group by title }').data.map do |r|
r['title']
end.uniq
end
end

def classes
self.class.classes
end

def self.resources
@@resources ||= client.request('', 'resources[type] { nodes { deactivated is null } }').data.map do |r|
@@resources ||= client.request('', 'resources[type] { nodes { deactivated is null } group by type }').data.map do |r|
r['type']
end.uniq
end
end

def resources
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def pql_to_jgrep(query)
endpoint_cols = query.split('{').first
endpoint = endpoint_cols.split(/[\s\[]/).first
query.sub!(/^#{Regexp.quote(endpoint_cols)}\{\s*/, '')
query.sub!(/(group\s+by\s+(type|title))/, '')
query.sub!(/\s*}\s*/, '')
query.sub!(/(and\s+)?nodes\s*\{\s*deactivated\s+is\s+null\s*\}/, '')

Expand Down

0 comments on commit f61cd0b

Please sign in to comment.