@@ -261,19 +261,36 @@ def to_resource_shim(resource)
261
261
type_definition . create_attribute_in ( self , name , param_or_property , parent , options )
262
262
end
263
263
264
+ def self . rsapi_provider_get ( names = [ ] )
265
+ # If the cache has been marked as having all instances, then just return the
266
+ # full contents:
267
+ return rsapi_provider_get_cache . all if rsapi_provider_get_cache . cached_all? && names . empty?
268
+
269
+ fetched = if type_definition . feature? ( 'simple_get_filter' )
270
+ my_provider . get ( context , names )
271
+ else
272
+ my_provider . get ( context )
273
+ end
274
+
275
+ fetched . each do |resource_hash |
276
+ type_definition . check_schema ( resource_hash )
277
+ rsapi_provider_get_cache . add ( build_title ( type_definition , resource_hash ) , resource_hash )
278
+ end
279
+
280
+ if !type_definition . feature? ( 'simple_get_filter' ) || names . empty?
281
+ # Mark the cache as having all possible instances:
282
+ rsapi_provider_get_cache . cached_all
283
+ end
284
+
285
+ fetched
286
+ end
287
+
264
288
def self . instances
265
289
# puts 'instances'
266
290
# force autoloading of the provider
267
291
provider ( type_definition . name )
268
292
269
- initial_fetch = if type_definition . feature? ( 'simple_get_filter' )
270
- my_provider . get ( context , [ ] )
271
- else
272
- my_provider . get ( context )
273
- end
274
-
275
- initial_fetch . map do |resource_hash |
276
- type_definition . check_schema ( resource_hash )
293
+ rsapi_provider_get . map do |resource_hash |
277
294
# allow a :title from the provider to override the default
278
295
result = if resource_hash . key? :title
279
296
new ( title : resource_hash [ :title ] )
@@ -288,14 +305,9 @@ def self.instances
288
305
end
289
306
290
307
def refresh_current_state
291
- current_state = if type_definition . feature? ( 'simple_get_filter' )
292
- my_provider . get ( context , [ rsapi_title ] ) . find { |h | namevar_match? ( h ) }
293
- else
294
- my_provider . get ( context ) . find { |h | namevar_match? ( h ) }
295
- end
308
+ current_state = self . class . rsapi_provider_get ( [ rsapi_title ] ) . find { |h | namevar_match? ( h ) }
296
309
297
310
if current_state
298
- type_definition . check_schema ( current_state )
299
311
strict_check ( current_state )
300
312
else
301
313
current_state = if rsapi_title . is_a? Hash
0 commit comments