diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-02-07 15:57:41 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-02-21 14:32:17 -0800 |
commit | da6382072c9d926f1611b0e94dd37dbe87ab6896 (patch) | |
tree | 7b9ebeb9edc0c19888273590543dca3c887f4260 | |
parent | 221b7ca1ce37dbf10107c42ff221411311c90ee8 (diff) | |
download | chef-da6382072c9d926f1611b0e94dd37dbe87ab6896.tar.gz |
fixing cache invalidation perf issues
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/node/attribute_collections.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb index d59307cb44..652820826d 100644 --- a/lib/chef/node/attribute_collections.rb +++ b/lib/chef/node/attribute_collections.rb @@ -148,7 +148,7 @@ class Chef # also invalidate the cached `merged_attributes` on the root Attribute # object. - def delete(key, &block) + def delete(key, &block) # XXX: why did i do this here and not in define_method below? ret = super send_reset_cache(__path__) ret @@ -169,15 +169,17 @@ class Chef def [](key) value = super if !key?(key) - value = self.class.new({}, __root__) + value = convert_value({}, __path__ + [ key ]) self[key] = value + send_reset_cache(__path__ + [ key ]) + value else value end end def []=(key, value) - ret = super + ret = regular_writer(convert_key(key), convert_value(value, __path__ + [ key ])) send_reset_cache(__path__ + [ key ]) ret # rubocop:disable Lint/Void end @@ -192,7 +194,7 @@ class Chef # We override it here to convert hash or array values to VividMash or # AttrArray for consistency and to ensure that the added parts of the # attribute tree will have the correct cache invalidation behavior. - def convert_value(value) + def convert_value(value, path = nil) value.ensure_generated_cache! if value.respond_to?(:ensure_generated_cache!) case value when VividMash @@ -200,9 +202,9 @@ class Chef when AttrArray value when Hash - VividMash.new(value, __root__, __node__, __precedence__) + VividMash.new(value, __root__, __node__, __precedence__, path) when Array - AttrArray.new(value, __root__, __node__, __precedence__) + AttrArray.new(value, __root__, __node__, __precedence__, path) else value end |