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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8bc293e01a8e0b0f05d3d183092552f8136e76f7d08145aa354e0dc7c2693ba
4
- data.tar.gz: 905edad7a81274176e100eaa58b5ee798d985c97f4c6543dee7b6fe81fd57675
3
+ metadata.gz: df98e13e157dd1e7dc6bda49e350d020017ce7d28be3eec26f09bba70d1cbae8
4
+ data.tar.gz: c8d0ae6f11a94a1a5d3e0ebac55ac2572805036b89f59f685e09cf672e3d9a05
5
5
  SHA512:
6
- metadata.gz: 723cc217870d0640c81f94c692604b260dfa1c45b747693807bbd8f5ceb5557c01398bbe4f9313a844a430b685eee25c9910a2360ffddd124c4d8c759ce72689
7
- data.tar.gz: bdcf5cef68f33898f535a976a642fa1b4f1397a496f23e2519c35076935b5fe431e58b7a810ee243ef89596ada2f40dd522642233e46f50b395626d32142f727
6
+ metadata.gz: e896531ea63cdac8870cd6c977312080c2ae2600a9419fdf8f496eb1df37c008c53c42f420088c804cfa1c6dcac4fa3d8a4eb13a0ac76774cea6bde79940af1a
7
+ data.tar.gz: e8a1d63b0e95d30fef050f20a8a25e7bc864f1753010272068bdd7f5cc9ac7f4805bb583b4f0df01951d4b6c9e41a5d7061162c1f6d52800d4ba27259ecefece
@@ -1,5 +1,10 @@
1
1
  ## 2.3.0 (January 28, 2020)
2
2
 
3
+ Improvements:
4
+ - Allow specifying `start` and `finish` options to `counter_culture_fix_counts` (#279)
5
+
6
+ ## 2.3.0 (January 28, 2020)
7
+
3
8
  Improvements:
4
9
  - Allow using scopes in `column_names` (#272)
5
10
 
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
- reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported, :batch_size, :touch, :where, :verbose))
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.group(full_primary_key(relation_class)).find_in_batches(batch_size: batch_size) do |records|
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
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '2.3.0'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  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.3.0
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-02-03 00:00:00.000000000 Z
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