lib/attractor/calculators/base_calculator.rb in attractor-2.1.0 vs lib/attractor/calculators/base_calculator.rb in attractor-2.2.0
- old
+ new
@@ -25,15 +25,28 @@
start_date: @start_date,
ignores: @ignores
).report(false)
churn[:churn][:changes].map do |change|
- complexity, details = yield(change)
- Value.new(file_path: change[:file_path],
- churn: change[:times_changed],
- complexity: complexity,
- details: details,
- history: git_history_for_file(file_path: change[:file_path]))
+ history = git_history_for_file(file_path: change[:file_path])
+ commit = history&.first&.first
+
+ cached_value = Cache.read(file_path: change[:file_path])
+
+ if !cached_value.nil? && !cached_value.current_commit.nil? && cached_value.current_commit == commit
+ value = cached_value
+ else
+ complexity, details = yield(change)
+
+ value = Value.new(file_path: change[:file_path],
+ churn: change[:times_changed],
+ complexity: complexity,
+ details: details,
+ history: history)
+ Cache.write(file_path: change[:file_path], value: value)
+ end
+
+ value
end
end
private