Skip to content

Commit

Permalink
Cache str diffs (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink authored May 1, 2020
1 parent 34a5773 commit ed70a20
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/puppet/catalog-diff/comparer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppet/util/diff'
require 'digest'
module Puppet::CatalogDiff
module Comparer
# Creates an array of just the resource titles
Expand Down Expand Up @@ -109,7 +110,7 @@ def return_resource_diffs(r1, r2)
differences
end

def str_diff(str1, str2)
def do_str_diff(str1, str2)
paths = [str1,str2].collect do |s|
tempfile = Tempfile.new("puppet-diffing")
tempfile.open
Expand All @@ -121,5 +122,12 @@ def str_diff(str1, str2)
paths.each { |f| f.delete }
diff
end

def str_diff(str1, str2)
@@cached_str_diffs ||= {}
sum1 = Digest::MD5.hexdigest str1
sum2 = Digest::MD5.hexdigest str2
@@cached_str_diffs["#{sum1}/#{sum2}"] ||= do_str_diff(str1, str2)
end
end
end

0 comments on commit ed70a20

Please sign in to comment.