counter_culture 2.5.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +6 -0
- data/counter_culture.gemspec +1 -2
- data/lib/counter_culture.rb +0 -1
- data/lib/counter_culture/counter.rb +1 -1
- data/lib/counter_culture/extensions.rb +3 -4
- data/lib/counter_culture/reconciler.rb +7 -5
- data/lib/counter_culture/version.rb +1 -1
- data/lib/generators/counter_culture_generator.rb +1 -1
- metadata +7 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74fff95505913ba522b3ec93bc9101c375c7de5678744145a0e4959f2c267361
|
4
|
+
data.tar.gz: bc284f87da6f949e7d875b7f30c43accbe23ce5716601af9fc4143eb6346954d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e63708745c4ffbb727a1b4da61a0d027de76d7256ee5d9669fa0f18dfcc2b183f26ddc109f45d6af6fb68a79c040e73872f647e8453c7b801e390036601878eb
|
7
|
+
data.tar.gz: c58c36d4aaf450450d913ad93487c7012de5de0ba8bb4f99c83a3994b64e8aed19f04a0d62c0df21ceda862312b9c010af042857709d891f746e20403ef893f2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
## 2.7.0 (November 16, 2020)
|
2
|
+
|
3
|
+
Improvements:
|
4
|
+
- New `column_name` option for `counter_culture_fix_counts` (#300)
|
5
|
+
|
6
|
+
## 2.6.2 (October 21, 2020)
|
7
|
+
|
8
|
+
Improvements:
|
9
|
+
- Remove superfluous dependency to after_commit_action gem (#297)
|
10
|
+
|
11
|
+
## 2.6.1 (September 8, 2020)
|
12
|
+
|
13
|
+
Bugfixes:
|
14
|
+
- Address Ruby 2.7.0 deprecation warning (#292)
|
15
|
+
|
16
|
+
## 2.6.0 (July 29, 2020)
|
17
|
+
|
18
|
+
Improvements:
|
19
|
+
- Use []= method instead of attribute writer method internally to avoid conflicts with read-only attributes (#287)
|
20
|
+
- More detailed logging when performing reconciliation (#288)
|
21
|
+
|
22
|
+
## 2.5.1 (May 18, 2020)
|
23
|
+
|
24
|
+
Bugfixes:
|
25
|
+
- Fix migration generation in Rails 6+ (#281)
|
26
|
+
|
1
27
|
## 2.5.0 (May 12, 2020)
|
2
28
|
|
3
29
|
Bugfixes:
|
data/README.md
CHANGED
@@ -187,6 +187,8 @@ end
|
|
187
187
|
|
188
188
|
Now, the ```Category``` model will keep the counter cache in ```special_count``` up-to-date. Only products where ```special?``` returns true will affect the special_count.
|
189
189
|
|
190
|
+
If you would like to use this with `counter_culture_fix_counts`, make sure to also provide [the `column_names` configuration](#handling-dynamic-column-names).
|
191
|
+
|
190
192
|
### Totaling instead of counting
|
191
193
|
|
192
194
|
Instead of keeping a running count, you may want to automatically track a running total.
|
@@ -268,6 +270,10 @@ Product.counter_culture_fix_counts only: :category
|
|
268
270
|
Product.counter_culture_fix_counts only: [[:subcategory, :category]]
|
269
271
|
# will automatically fix counts only on the two-level [:subcategory, :category] relation on Product
|
270
272
|
|
273
|
+
Product.counter_culture_fix_counts column_name: :reviews_count
|
274
|
+
# will automatically fix counts only on the :reviews_count column on Product
|
275
|
+
# This allows us to skip the columns that have already been processed. This is useful after running big DB changes that affect only one counter cache column.
|
276
|
+
|
271
277
|
# :except and :only also accept arrays
|
272
278
|
|
273
279
|
Product.counter_culture_fix_counts verbose: true
|
data/counter_culture.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = 'Turbo-charged counter caches for your Rails app.'
|
12
12
|
spec.description = 'counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback.'
|
13
|
-
spec.homepage = '
|
13
|
+
spec.homepage = 'https://github.com/magnusvk/counter_culture'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
-
spec.add_dependency 'after_commit_action', '~> 1.0'
|
29
28
|
spec.add_dependency 'activerecord', '>= 4.2'
|
30
29
|
spec.add_dependency 'activesupport', '>= 4.2'
|
31
30
|
|
data/lib/counter_culture.rb
CHANGED
@@ -290,7 +290,7 @@ module CounterCulture
|
|
290
290
|
changes_method = ACTIVE_RECORD_VERSION >= Gem::Version.new("5.1.0") ? :saved_changes : :changed_attributes
|
291
291
|
obj.public_send(changes_method).each do |key, value|
|
292
292
|
old_value = ACTIVE_RECORD_VERSION >= Gem::Version.new("5.1.0") ? value.first : value
|
293
|
-
prev
|
293
|
+
prev[key] = old_value
|
294
294
|
end
|
295
295
|
|
296
296
|
prev
|
@@ -15,8 +15,6 @@ module CounterCulture
|
|
15
15
|
# called to configure counter caches
|
16
16
|
def counter_culture(relation, options = {})
|
17
17
|
unless @after_commit_counter_cache
|
18
|
-
include AfterCommitAction unless include?(AfterCommitAction)
|
19
|
-
|
20
18
|
# initialize callbacks only once
|
21
19
|
after_create :_update_counts_after_create
|
22
20
|
|
@@ -61,7 +59,8 @@ module CounterCulture
|
|
61
59
|
#
|
62
60
|
# options:
|
63
61
|
# { :exclude => list of relations to skip when fixing counts,
|
64
|
-
# :only => only these relations will have their counts fixed
|
62
|
+
# :only => only these relations will have their counts fixed,
|
63
|
+
# :column_name => only this column will have its count fixed }
|
65
64
|
# returns: a list of fixed record as an array of hashes of the form:
|
66
65
|
# { :entity => which model the count was fixed on,
|
67
66
|
# :id => the id of the model that had the incorrect count,
|
@@ -81,7 +80,7 @@ module CounterCulture
|
|
81
80
|
next if options[:exclude] && options[:exclude].include?(counter.relation)
|
82
81
|
next if options[:only] && !options[:only].include?(counter.relation)
|
83
82
|
|
84
|
-
reconciler_options = %i(batch_size finish skip_unsupported start touch verbose where)
|
83
|
+
reconciler_options = %i(batch_size column_name finish skip_unsupported start touch verbose where)
|
85
84
|
|
86
85
|
reconciler = CounterCulture::Reconciler.new(counter, options.slice(*reconciler_options))
|
87
86
|
reconciler.reconcile!
|
@@ -76,6 +76,10 @@ module CounterCulture
|
|
76
76
|
|
77
77
|
counter_column_names = column_names || {nil => counter_cache_name}
|
78
78
|
|
79
|
+
if options[:column_name]
|
80
|
+
counter_column_names = counter_column_names.select{ |_, v| options[:column_name].to_s == v }
|
81
|
+
end
|
82
|
+
|
79
83
|
# iterate over all the possible counter cache column names
|
80
84
|
counter_column_names.each do |where, column_name|
|
81
85
|
# if the column name is nil, that means those records don't affect
|
@@ -102,8 +106,6 @@ module CounterCulture
|
|
102
106
|
# iterate in batches; otherwise we might run out of memory when there's a lot of
|
103
107
|
# instances and we try to load all their counts at once
|
104
108
|
batch_size = options.fetch(:batch_size, CounterCulture.config.batch_size)
|
105
|
-
start_index = options[:start]
|
106
|
-
finish_index = options[:finish]
|
107
109
|
|
108
110
|
counts_query = counts_query.where(options[:where]).group(full_primary_key(relation_class))
|
109
111
|
|
@@ -111,9 +113,11 @@ module CounterCulture
|
|
111
113
|
find_in_batches_args[:start] = options[:start] if options[:start].present?
|
112
114
|
find_in_batches_args[:finish] = options[:finish] if options[:finish].present?
|
113
115
|
|
114
|
-
counts_query.find_in_batches(find_in_batches_args) do |records|
|
116
|
+
counts_query.find_in_batches(**find_in_batches_args).with_index(1) do |records, index|
|
117
|
+
log "Processing batch ##{index}."
|
115
118
|
# now iterate over all the models and see whether their counts are right
|
116
119
|
update_count_for_batch(column_name, records)
|
120
|
+
log "Finished batch ##{index}."
|
117
121
|
end
|
118
122
|
end
|
119
123
|
log_without_newline "\n"
|
@@ -123,8 +127,6 @@ module CounterCulture
|
|
123
127
|
private
|
124
128
|
|
125
129
|
def update_count_for_batch(column_name, records)
|
126
|
-
log_without_newline "."
|
127
|
-
|
128
130
|
ActiveRecord::Base.transaction do
|
129
131
|
records.each do |record|
|
130
132
|
count = record.read_attribute('count') || 0
|
@@ -27,7 +27,7 @@ class CounterCultureGenerator < ActiveRecord::Generators::Base
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def migration_version
|
30
|
-
if Rails.version.
|
30
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0')
|
31
31
|
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: counter_culture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus von Koeller
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: after_commit_action
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: activerecord
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -285,11 +271,11 @@ files:
|
|
285
271
|
- lib/generators/counter_culture_generator.rb
|
286
272
|
- lib/generators/templates/counter_culture_migration.rb.erb
|
287
273
|
- run_tests_locally.sh
|
288
|
-
homepage:
|
274
|
+
homepage: https://github.com/magnusvk/counter_culture
|
289
275
|
licenses:
|
290
276
|
- MIT
|
291
277
|
metadata: {}
|
292
|
-
post_install_message:
|
278
|
+
post_install_message:
|
293
279
|
rdoc_options: []
|
294
280
|
require_paths:
|
295
281
|
- lib
|
@@ -304,9 +290,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
290
|
- !ruby/object:Gem::Version
|
305
291
|
version: '0'
|
306
292
|
requirements: []
|
307
|
-
|
308
|
-
|
309
|
-
signing_key:
|
293
|
+
rubygems_version: 3.1.4
|
294
|
+
signing_key:
|
310
295
|
specification_version: 4
|
311
296
|
summary: Turbo-charged counter caches for your Rails app.
|
312
297
|
test_files: []
|