From 95742a8a266d644da212344a184a6de3459ab26a Mon Sep 17 00:00:00 2001 From: Sean Millichamp Date: Tue, 2 Apr 2024 16:33:25 +0000 Subject: [PATCH] Improve inventory target name resolution performance When resolving a large number of targets from a plan the match_wildcard? regex is compiled on the fly possibly hundreds or thousands (for a large inventory) of times per target name resolution. Switching to File.fnmatch provides a significant speed increase and seems to more accurately reflect the functionality stated in the Bolt documentation with regards to target matching. --- lib/bolt/inventory/inventory.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bolt/inventory/inventory.rb b/lib/bolt/inventory/inventory.rb index 82a688bc7b..54d67b387c 100644 --- a/lib/bolt/inventory/inventory.rb +++ b/lib/bolt/inventory/inventory.rb @@ -119,8 +119,7 @@ def match_wildcard?(wildcard, target_name, ext_glob: false) if ext_glob File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD | File::FNM_EXTGLOB) else - regexp = Regexp.new("^#{Regexp.escape(wildcard).gsub('\*', '.*?')}$", Regexp::IGNORECASE) - target_name =~ regexp + File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD) end end