Skip to content

Commit 7903a91

Browse files
authored
Merge branch 'main' into CAT-2327-Temporary_revert_of_cache_changes
2 parents 2a22428 + 3db3c68 commit 7903a91

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/puppet/resource_api.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,42 @@ def to_resource_shim(resource)
242242
type_definition.create_attribute_in(self, name, param_or_property, parent, options)
243243
end
244244

245+
def self.rsapi_provider_get(names = nil)
246+
# If the cache has been marked as having all instances, then just return the
247+
# full contents or the filtered contents based on names:
248+
if rsapi_provider_get_cache.cached_all?
249+
return rsapi_provider_get_cache.all if names.nil?
250+
251+
# If we have all instances cached but need specific ones, filter from cache
252+
cached_resources = names.map { |name| rsapi_provider_get_cache.get(name) }.compact
253+
return cached_resources unless cached_resources.empty?
254+
end
255+
256+
# For simple_get_filter, if we're asking for specific resources and they're cached, return those
257+
if type_definition.feature?('simple_get_filter') && !names.nil?
258+
cached_resources = names.map { |name| rsapi_provider_get_cache.get(name) }.compact
259+
return cached_resources if names.length == cached_resources.length
260+
end
261+
262+
fetched = if type_definition.feature?('simple_get_filter')
263+
my_provider.get(context, names)
264+
else
265+
my_provider.get(context)
266+
end
267+
268+
fetched.each do |resource_hash|
269+
type_definition.check_schema(resource_hash)
270+
rsapi_provider_get_cache.add(build_title(type_definition, resource_hash), resource_hash)
271+
end
272+
273+
if names.nil? && !type_definition.feature?('simple_get_filter')
274+
# Mark the cache as having all possible instances:
275+
rsapi_provider_get_cache.cached_all
276+
end
277+
278+
fetched
279+
end
280+
245281
def self.instances
246282
# puts 'instances'
247283
# force autoloading of the provider

0 commit comments

Comments
 (0)