counter_culture 3.4.0 → 3.5.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: 749d2a26a921731dd342cddd6d9e479776b26eb3ccd836fb703e47bca4c05b22
4
- data.tar.gz: f59ff08373a8831c2f96605bf75063b5d50d6f1adecfa0486a53d41a3c9a8b9b
3
+ metadata.gz: acebc4b3981511ea35497a3f276372253cb709314002ab2c6c498fb9b60a0166
4
+ data.tar.gz: b659b8956b8e6911c58563e4f921487f49a3ddf8ada5fbee7b79b0de16f8796d
5
5
  SHA512:
6
- metadata.gz: 3a57f1f22ce98c08ccf76552a040445bbcf37f53966bf3abde13f2be2fcb9c4abbf3ea13f8e911ffd536122f161e04cb0a6b62b0a1330435c2568bd8d06c39ac
7
- data.tar.gz: f29b2abad46f30de69df23e0e02fa0bcb75447fd2dd854cc42dc979efbe9955316984285ae68bfd3033e4e0d8a2d31bc06699a667b2c375306e654ac2eaff8f7
6
+ metadata.gz: 9ef804972ebbd99b5945b22d87c85d93dcd3af1ea78f04683a0799b67d25d42cb8c4ca52e08b9267fbd17f11e6fcd07a334e5990cccd5e4fd3ea27991da67fb4
7
+ data.tar.gz: 81fa1adc6e283a1fed1a661e08cc7bd4a5280062cb8567ef730ce59342b0cf49032d09a9fc05bcbff713fbbd37d9a7157f2de35bc25df696d48f5de5bed9281c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.5.0 (August 25, 2023)
2
+
3
+ Improvements:
4
+ - Allow passing context to `counter_culture_fix_counts` (#375)
5
+
1
6
  ## 3.4.0 (July 12, 2023)
2
7
 
3
8
  Improvements:
data/README.md CHANGED
@@ -267,7 +267,7 @@ With this option, any time the `category_counter_cache` changes both the `catego
267
267
 
268
268
  Some applications run into issues with deadlocks involving counter cache updates when using this gem. See [#263](https://github.com/magnusvk/counter_culture/issues/263#issuecomment-772284439) for information and helpful links on how to avoid this issue.
269
269
 
270
- Another option is to simply defer the update of counter caches to outside of the transaction. This gives up transacrtional guarantees for your counter cache updates but should resolve any deadlocks you experience. This behavior is disabled by default, enable it on each affected counter cache as follows:
270
+ Another option is to simply defer the update of counter caches to outside of the transaction. This gives up transactional guarantees for your counter cache updates but should resolve any deadlocks you experience. This behavior is disabled by default, enable it on each affected counter cache as follows:
271
271
 
272
272
  ```ruby
273
273
  counter_culture :category, execute_after_commit: true
@@ -431,6 +431,23 @@ dynamic, you can pass `skip_unsupported`:
431
431
  Product.counter_culture_fix_counts skip_unsupported: true
432
432
  ```
433
433
 
434
+ You can also use context within the block that was provided with the `column_names` method:
435
+
436
+ ```ruby
437
+ class Product < ActiveRecord::Base
438
+ belongs_to :category
439
+ scope :awesomes, -> (ids) { where(ids: ids, product_type: 'awesome') }
440
+
441
+ counter_culture :category,
442
+ column_name: 'awesome_count'
443
+ column_names: -> (context) {
444
+ { Product.awesomes(context[:ids]) => :awesome_count }
445
+ }
446
+ end
447
+
448
+ Product.counter_culture_fix_counts(context: { ids: [1, 2] })
449
+ ```
450
+
434
451
  #### Handling over-written, dynamic foreign keys
435
452
 
436
453
  Manually populating counter caches with dynamically over-written foreign keys (```:foreign_key_values``` option) is not supported. You will have to write code to handle this case yourself.
@@ -84,7 +84,7 @@ module CounterCulture
84
84
  next if options[:exclude] && options[:exclude].include?(counter.relation)
85
85
  next if options[:only] && !options[:only].include?(counter.relation)
86
86
 
87
- reconciler_options = %i(batch_size column_name db_connection_builder finish skip_unsupported start touch verbose where polymorphic_classes)
87
+ reconciler_options = %i(context batch_size column_name db_connection_builder finish skip_unsupported start touch verbose where polymorphic_classes)
88
88
 
89
89
  reconciler = CounterCulture::Reconciler.new(counter, options.slice(*reconciler_options))
90
90
  reconciler.reconcile!
@@ -77,7 +77,11 @@ module CounterCulture
77
77
  counter_column_names =
78
78
  case column_names
79
79
  when Proc
80
- column_names.call
80
+ if column_names.lambda? && column_names.arity == 0
81
+ column_names.call
82
+ else
83
+ column_names.call(options.fetch(:context, {}))
84
+ end
81
85
  when Hash
82
86
  column_names
83
87
  else
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.4.0'.freeze
2
+ VERSION = '3.5.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: 3.4.0
4
+ version: 3.5.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: 2023-07-13 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
344
  - !ruby/object:Gem::Version
345
345
  version: '0'
346
346
  requirements: []
347
- rubygems_version: 3.4.10
347
+ rubygems_version: 3.4.19
348
348
  signing_key:
349
349
  specification_version: 4
350
350
  summary: Turbo-charged counter caches for your Rails app.