summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-02-07 15:57:41 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-02-07 15:57:41 -0800
commitf4e8476902af44c342c9b162ae8faba7142ce3b6 (patch)
tree80727f773058ac2aa1930ab71aba88a702ab53ae
parentf6f0569d5388acac8aaf5d1a56961fa4c24d1521 (diff)
downloadchef-f4e8476902af44c342c9b162ae8faba7142ce3b6.tar.gz
fixing cache invalidation perf issues
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/attribute_collections.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index 05ddf998aa..4e27f82aae 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
@@ -210,7 +212,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
@@ -218,9 +220,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