lib/counter_culture/extensions.rb in counter_culture-3.2.1 vs lib/counter_culture/extensions.rb in counter_culture-3.3.0
- old
+ new
@@ -43,19 +43,11 @@
# we keep a list of all counter caches we must maintain
@after_commit_counter_cache = []
end
- column_names_valid = (
- !options[:column_names] ||
- options[:column_names].is_a?(Hash) ||
- (
- options[:column_names].is_a?(Proc) &&
- options[:column_names].call.is_a?(Hash)
- )
- )
- unless column_names_valid
+ if options[:column_names] && !(options[:column_names].is_a?(Hash) || options[:column_names].is_a?(Proc))
raise ArgumentError.new(
":column_names must be a Hash of conditions and column names, " \
"or a Proc that when called returns such a Hash"
)
end
@@ -90,11 +82,11 @@
@after_commit_counter_cache.flat_map do |counter|
next if options[:exclude] && options[:exclude].include?(counter.relation)
next if options[:only] && !options[:only].include?(counter.relation)
- reconciler_options = %i(batch_size column_name finish skip_unsupported start touch verbose where polymorphic_classes)
+ reconciler_options = %i(batch_size column_name db_connection_builder finish skip_unsupported start touch verbose where polymorphic_classes)
reconciler = CounterCulture::Reconciler.new(counter, options.slice(*reconciler_options))
reconciler.reconcile!
reconciler.changes
end.compact
@@ -111,11 +103,13 @@
end
# called by after_destroy callback
def _update_counts_after_destroy
self.class.after_commit_counter_cache.each do |counter|
- # decrement counter cache
- counter.change_counter_cache(self, :increment => false)
+ unless destroyed?
+ # decrement counter cache
+ counter.change_counter_cache(self, :increment => false)
+ end
end
end
# called by after_update callback
def _update_counts_after_update