counter_culture 2.3.0 → 2.4.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 +5 -0
- data/README.md +20 -1
- data/lib/counter_culture/extensions.rb +3 -1
- data/lib/counter_culture/reconciler.rb +4 -2
- data/lib/counter_culture/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df98e13e157dd1e7dc6bda49e350d020017ce7d28be3eec26f09bba70d1cbae8
|
4
|
+
data.tar.gz: c8d0ae6f11a94a1a5d3e0ebac55ac2572805036b89f59f685e09cf672e3d9a05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e896531ea63cdac8870cd6c977312080c2ae2600a9419fdf8f496eb1df37c008c53c42f420088c804cfa1c6dcac4fa3d8a4eb13a0ac76774cea6bde79940af1a
|
7
|
+
data.tar.gz: e8a1d63b0e95d30fef050f20a8a25e7bc864f1753010272068bdd7f5cc9ac7f4805bb583b4f0df01951d4b6c9e41a5d7061162c1f6d52800d4ba27259ecefece
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -309,7 +309,26 @@ Product.counter_culture_fix_counts touch: true
|
|
309
309
|
If you have specified a custom timestamps column, pass its name as the value for the `touch` option:
|
310
310
|
|
311
311
|
```ruby
|
312
|
-
Product.counter_culture_fix_counts touch: category_count_changed
|
312
|
+
Product.counter_culture_fix_counts touch: 'category_count_changed'
|
313
|
+
```
|
314
|
+
|
315
|
+
|
316
|
+
#### Parallelizing fix counter cache in multiple workers
|
317
|
+
|
318
|
+
The options start and finish are especially useful if you want multiple workers dealing with the same processing queue. You can make worker 1 handle all the records between id 1 and 9999 and worker 2 handle from 10000 and beyond by setting the :start and :finish option on each worker.
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
Product.counter_culture_fix_counts start: 10_000
|
322
|
+
# will fix counts for all counter caches defined on Product from record 10000 and onwards.
|
323
|
+
|
324
|
+
Product.counter_culture_fix_counts finish: 10_000
|
325
|
+
# let's process until 10000 records.
|
326
|
+
|
327
|
+
Product.counter_culture_fix_counts start: 1000, finish: 2000
|
328
|
+
# In worker 1, lets process from 1000 to 2000
|
329
|
+
|
330
|
+
Product.counter_culture_fix_counts start: 2001, finish: 3000
|
331
|
+
# In worker 2, lets process from 2001 to 3000
|
313
332
|
```
|
314
333
|
|
315
334
|
#### Handling dynamic column names
|
@@ -81,7 +81,9 @@ module CounterCulture
|
|
81
81
|
next if options[:exclude] && options[:exclude].include?(counter.relation)
|
82
82
|
next if options[:only] && !options[:only].include?(counter.relation)
|
83
83
|
|
84
|
-
|
84
|
+
reconciler_options = %i(batch_size finish skip_unsupported start touch verbose where)
|
85
|
+
|
86
|
+
reconciler = CounterCulture::Reconciler.new(counter, options.slice(*reconciler_options))
|
85
87
|
reconciler.reconcile!
|
86
88
|
reconciler.changes
|
87
89
|
end.compact
|
@@ -102,10 +102,12 @@ module CounterCulture
|
|
102
102
|
# iterate in batches; otherwise we might run out of memory when there's a lot of
|
103
103
|
# instances and we try to load all their counts at once
|
104
104
|
batch_size = options.fetch(:batch_size, CounterCulture.config.batch_size)
|
105
|
+
start_index = options[:start]
|
106
|
+
finish_index = options[:finish]
|
105
107
|
|
106
|
-
counts_query = counts_query.where(options[:where])
|
108
|
+
counts_query = counts_query.where(options[:where]).group(full_primary_key(relation_class))
|
107
109
|
|
108
|
-
counts_query.
|
110
|
+
counts_query.find_in_batches(batch_size: batch_size, start: start_index, finish: finish_index) do |records|
|
109
111
|
# now iterate over all the models and see whether their counts are right
|
110
112
|
update_count_for_batch(column_name, records)
|
111
113
|
end
|
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus von Koeller
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_commit_action
|