Module: CounterCulture
- Defined in:
- lib/counter_culture.rb,
lib/counter_culture/counter.rb,
lib/counter_culture/version.rb,
lib/counter_culture/extensions.rb,
lib/counter_culture/reconciler.rb,
lib/counter_culture/skip_updates.rb,
lib/counter_culture/configuration.rb,
lib/counter_culture/with_connection.rb
Defined Under Namespace
Modules: Extensions, SkipUpdates
Classes: Configuration, Counter, Reconciler, WithConnection
Constant Summary
collapse
- VERSION =
'3.12.1'.freeze
Class Method Summary
collapse
Class Method Details
.aggregate_counter_updates ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/counter_culture.rb', line 20
def self.aggregate_counter_updates
return unless block_given?
Thread.current[:aggregate_counter_updates] = true
Thread.current[:aggregated_updates] = {}
Thread.current[:primary_key_map] = {}
result = yield
Thread.current[:aggregated_updates].each do |klass, attrs|
attrs.each do |rec_id, updates|
arel_updates = {}
updates[:counters].each do |column, info|
next if info[:delta] == 0
arel_updates[column] = Counter.build_arel_counter_expr(klass, column, info[:delta], info[:type])
end
if updates[:timestamps].any?
current_time = klass.send(:current_time_from_proper_timezone)
updates[:timestamps].each do |column|
arel_updates[column] = current_time
end
end
if arel_updates.any?
primary_key = Thread.current[:primary_key_map][klass]
conditions =
Array.wrap(primary_key)
.zip(Array.wrap(rec_id))
.to_h
klass.where(conditions).distinct(false).update_all(arel_updates)
end
end
end
result
ensure
Thread.current[:aggregate_counter_updates] = false
Thread.current[:aggregated_updates] = nil
Thread.current[:primary_key_map] = nil
end
|
.config {|_self| ... } ⇒ Object
15
16
17
18
|
# File 'lib/counter_culture.rb', line 15
def self.config
yield(self) if block_given?
self
end
|
.configuration ⇒ Object
2
3
4
|
# File 'lib/counter_culture/configuration.rb', line 2
def self.configuration
@configuration ||= Configuration.new
end
|
6
7
8
|
# File 'lib/counter_culture/configuration.rb', line 6
def self.configure
yield(configuration)
end
|
.reset_configuration ⇒ Object
10
11
12
|
# File 'lib/counter_culture/configuration.rb', line 10
def self.reset_configuration
@configuration = Configuration.new
end
|
.supports_composite_keys? ⇒ Boolean
14
15
16
|
# File 'lib/counter_culture/configuration.rb', line 14
def self.supports_composite_keys?
Gem::Requirement.new('>= 7.2.0').satisfied_by?(ActiveRecord.version)
end
|