From 592b7b3e8b5387a12aab6e2d143b4e000b124366 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Fri, 19 Jan 2024 09:09:52 -0600 Subject: [PATCH] optimize puppetdb query --- lib/puppet-ghostbuster/puppetdb.rb | 8 ++++---- spec/spec_helper.rb | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/puppet-ghostbuster/puppetdb.rb b/lib/puppet-ghostbuster/puppetdb.rb index f6fa532..e105fdc 100644 --- a/lib/puppet-ghostbuster/puppetdb.rb +++ b/lib/puppet-ghostbuster/puppetdb.rb @@ -40,9 +40,9 @@ 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 @@ -50,9 +50,9 @@ def 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fceefe0..6f4af69 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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*\}/, '')