counter_culture 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +3 -3
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -3
- data/lib/counter_culture/extensions.rb +1 -1
- data/lib/counter_culture/reconciler.rb +15 -11
- data/spec/counter_culture_spec.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b21a580a6873b3d63ccddaf37e9ab42da83665d8
|
4
|
+
data.tar.gz: eb40b01c09c04572acae15638170a54a18ceea70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1415bf5f64587fd1fb7b6c0ab3903b4a6f0da32f7d9570c3b35d11cd4b33c0b8059fb91cd80547c270362872028fdf720b8c87d402928e77e2179059e18916cc
|
7
|
+
data.tar.gz: 0b729a1911b0a38d9acc9ad9f02f22895b1e92a7b1af39f1dd3010c5ec5705ae7eea248b7c07ab236eca255ef277626caaecdb48b5d85deec33e753c82d6cd60
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
## 1.8.
|
1
|
+
## 1.8.2 (September 27, 2017)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
- Actually use `batch_size` parameter in `counter_culture_fix_counts` (#200)
|
5
|
+
|
6
|
+
## 1.8.1 (September 5, 2017)
|
2
7
|
|
3
8
|
Improvements:
|
4
9
|
- Use ActiveRecord version, not Rails version, in `Reconciler`, makeing it possible to use `counter_culture_fix_counts` without Rails
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Tested against Ruby 2.2.5 and 2.3.1 and against the latest patch releases of Rai
|
|
14
14
|
Add counter_culture to your Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'counter_culture', '~> 1.
|
17
|
+
gem 'counter_culture', '~> 1.8'
|
18
18
|
```
|
19
19
|
|
20
20
|
Then run `bundle install`
|
@@ -234,13 +234,13 @@ You will sometimes want to populate counter-cache values from primary data. This
|
|
234
234
|
Product.counter_culture_fix_counts
|
235
235
|
# will automatically fix counts for all counter caches defined on Product
|
236
236
|
|
237
|
-
Product.counter_culture_fix_counts
|
237
|
+
Product.counter_culture_fix_counts exclude: :category
|
238
238
|
# will automatically fix counts for all counter caches defined on Product, except for the :category relation
|
239
239
|
|
240
240
|
Product.counter_culture_fix_counts only: :category
|
241
241
|
# will automatically fix counts only on the :category relation on Product
|
242
242
|
|
243
|
-
# :
|
243
|
+
# :exclude and :only also accept arrays of one level relations
|
244
244
|
# if you want to fix counts on a more than one level relation you need to use convention below:
|
245
245
|
|
246
246
|
Product.counter_culture_fix_counts only: [[:subcategory, :category]]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.2
|
data/counter_culture.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: counter_culture 1.8.
|
5
|
+
# stub: counter_culture 1.8.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "counter_culture"
|
9
|
-
s.version = "1.8.
|
9
|
+
s.version = "1.8.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Magnus von Koeller"]
|
14
|
-
s.date = "2017-09-
|
14
|
+
s.date = "2017-09-27"
|
15
15
|
s.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."
|
16
16
|
s.email = "magnus@vonkoeller.de"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -63,7 +63,7 @@ module CounterCulture
|
|
63
63
|
next if options[:exclude] && options[:exclude].include?(counter.relation)
|
64
64
|
next if options[:only] && !options[:only].include?(counter.relation)
|
65
65
|
|
66
|
-
reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported))
|
66
|
+
reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported, :batch_size))
|
67
67
|
reconciler.reconcile!
|
68
68
|
reconciler.changes
|
69
69
|
end.compact
|
@@ -99,23 +99,27 @@ module CounterCulture
|
|
99
99
|
|
100
100
|
counts_query.group(full_primary_key(relation_class)).find_in_batches(batch_size: batch_size) do |records|
|
101
101
|
# now iterate over all the models and see whether their counts are right
|
102
|
-
|
103
|
-
records.each do |record|
|
104
|
-
count = record.read_attribute('count') || 0
|
105
|
-
next if record.read_attribute(column_name) == count
|
106
|
-
|
107
|
-
track_change(record, column_name, count)
|
108
|
-
|
109
|
-
# use update_all because it's faster and because a fixed counter-cache shouldn't update the timestamp
|
110
|
-
relation_class.where(relation_class.primary_key => record.send(relation_class.primary_key)).update_all(column_name => count)
|
111
|
-
end
|
112
|
-
end
|
102
|
+
update_count_for_batch(column_name, records)
|
113
103
|
end
|
114
104
|
end
|
115
105
|
end
|
116
106
|
|
117
107
|
private
|
118
108
|
|
109
|
+
def update_count_for_batch(column_name, records)
|
110
|
+
ActiveRecord::Base.transaction do
|
111
|
+
records.each do |record|
|
112
|
+
count = record.read_attribute('count') || 0
|
113
|
+
next if record.read_attribute(column_name) == count
|
114
|
+
|
115
|
+
track_change(record, column_name, count)
|
116
|
+
|
117
|
+
# use update_all because it's faster and because a fixed counter-cache shouldn't update the timestamp
|
118
|
+
relation_class.where(relation_class.primary_key => record.send(relation_class.primary_key)).update_all(column_name => count)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
119
123
|
# keep track of what we fixed, e.g. for a notification email
|
120
124
|
def track_change(record, column_name, count)
|
121
125
|
@changes_holder << {
|
@@ -34,7 +34,6 @@ describe "CounterCulture" do
|
|
34
34
|
DatabaseCleaner.clean
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
37
|
it "should use relation foreign_key correctly" do
|
39
38
|
post = AnotherPost.new
|
40
39
|
comment = post.comments.build
|
@@ -1276,6 +1275,21 @@ describe "CounterCulture" do
|
|
1276
1275
|
A_FEW = CI_TEST_RUN ? 50: 10
|
1277
1276
|
A_BATCH = CI_TEST_RUN ? 100: 10
|
1278
1277
|
|
1278
|
+
it "should support batch processing" do
|
1279
|
+
# first, clean up
|
1280
|
+
SimpleDependent.delete_all
|
1281
|
+
SimpleMain.delete_all
|
1282
|
+
|
1283
|
+
expect_any_instance_of(CounterCulture::Reconciler::Reconciliation).to receive(:update_count_for_batch).exactly(MANY/A_BATCH).times
|
1284
|
+
|
1285
|
+
MANY.times do |i|
|
1286
|
+
main = SimpleMain.create
|
1287
|
+
3.times { main.simple_dependents.create }
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
SimpleDependent.counter_culture_fix_counts :batch_size => A_BATCH
|
1291
|
+
end
|
1292
|
+
|
1279
1293
|
it "should correctly fix the counter caches with thousands of records" do
|
1280
1294
|
# first, clean up
|
1281
1295
|
SimpleDependent.delete_all
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: counter_culture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus von Koeller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_commit_action
|