Skip to content

Commit 59772ca

Browse files
author
Amanda Harth
committed
Use cached get() results to limit calls to get()
My understanding... there may be cases I haven't considered. In my testing, with simple_get_filter not implemented, removing the names.nil? checks stopped get(context) being called again for every resource which had pending changes. All resources of the given type were collected from the system with one get() call and cached. Subsequent calls to rsapi_provider_get returned the cached information. When simple_get_filter is not implemented: 1. The cached data is returned, if the cache has been marked as complete and names is nil. 2. Therefore, if names is NOT nil or if the cache hasn't been marked complete, information about all resources of the given type is fetched by calling the provider's get() function. 3. The fetched information for all relevant resources is added to the cache. 4. The cache is marked complete if names is nil and simple_get_feature is not implemented. 5. Subsequent calls to rsapi_provider_get (e.g. to retrieve the current state of a resource which has pending changes) pass in a value for 'names', and therefore names.nil? is false, and the cache in point 1 above isn't returned or used. get() is therefore called again per resource to retrieve all resource information again. Removing the names.nil? checks on lines 255 and 268 allows the cache to be populated with information about all of the resources of the given type with one get() call, mark the cache as complete, and therefore allow the cache to be used in subsequent calls to rsapi_provider_get for each resource. Simple_get_filter behaviour wouldn't change, as when simple_get_filter is implemented the cache would never be marked as complete or returned: my_provider.get(context, names) would still be called every time.
1 parent e4a8fc8 commit 59772ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/puppet/resource_api.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def to_resource_shim(resource)
252252
def self.rsapi_provider_get(names = nil)
253253
# If the cache has been marked as having all instances, then just return the
254254
# full contents:
255-
return rsapi_provider_get_cache.all if rsapi_provider_get_cache.cached_all? && names.nil?
255+
return rsapi_provider_get_cache.all if rsapi_provider_get_cache.cached_all?
256256

257257
fetched = if type_definition.feature?('simple_get_filter')
258258
my_provider.get(context, names)
@@ -265,7 +265,7 @@ def self.rsapi_provider_get(names = nil)
265265
rsapi_provider_get_cache.add(build_title(type_definition, resource_hash), resource_hash)
266266
end
267267

268-
if names.nil? && !type_definition.feature?('simple_get_filter')
268+
if !type_definition.feature?('simple_get_filter')
269269
# Mark the cache as having all possible instances:
270270
rsapi_provider_get_cache.cached_all
271271
end

0 commit comments

Comments
 (0)