counter_culture 3.13.3 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c24eb92adf8139552bb89de6d5f39f41f1fc46b89a9b23f66309385ab31cb6f
4
- data.tar.gz: b3ec3a46a8bcaa1520b193a47909d3233c0193958849caac5cbe580acc621316
3
+ metadata.gz: 55a968373b0c0e7f763a62f22c1fcee0156a27227a605d07d85dc464d9973873
4
+ data.tar.gz: b2c63fa6c9c9be56a8511e39663c82ede80e8a07d49d0991c2e7a0cd7c69d2c8
5
5
  SHA512:
6
- metadata.gz: fd20102f237e5a2a3757567339afb5c60d5ef87e6d97c411a2e51a365749e1e45482a63553d631bf8337cbce997d657c708a34a7bf8a4a7d84b87dfd77d241b8
7
- data.tar.gz: 533d50714673ce1e209db0e7ebbf29717668783014d3753d15306f6e0705c042a50821602ca948ed1444ec5adc76799c059e5735c5db0f416b6664f4fc414459
6
+ metadata.gz: ba7889dd178c96cff2b98b111ff7129dbba01c5e73f419c5a68489850ddf0bca205dd03e23302994a517b82a592a2967db6c39598a5b286420dbb166bb04c977
7
+ data.tar.gz: e2261e735bccf84dd64549788facecd1fa7d240ef450852b69be596f57a4f93c3a9db63227e64bc9dd02380aab3c78c9c7d7decae12070187c242a3f96db14e6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 3.14.0 (June 26, 2026)
2
+
3
+ New features:
4
+ - Use the built-in `ActiveRecord.after_all_transactions_commit` API for `execute_after_commit` on Rails 7.2+, so the `after_commit_action` gem is no longer required on modern Rails. Older Rails versions keep using the gem as before.
5
+
6
+ Changes:
7
+ - On Rails 7.2+, counter_culture no longer mixes the `after_commit_action` gem's `AfterCommitAction` module into models that use `execute_after_commit`. If your own code called the `execute_after_commit` instance method on those models (relying on counter_culture to make it available), add the `after_commit_action` gem and `include AfterCommitAction` yourself.
8
+
1
9
  ## 3.13.3 (June 25, 2026)
2
10
 
3
11
  Bugfixes:
data/README.md CHANGED
@@ -272,7 +272,7 @@ Another option is to simply defer the update of counter caches to outside of the
272
272
  ```ruby
273
273
  counter_culture :category, execute_after_commit: true
274
274
  ```
275
- [NOTE] You need to manually specify the `after_commit_action` as dependency in the Gemfile to use this feature
275
+ [NOTE] On Rails 7.2 and newer this uses the built-in `ActiveRecord.after_all_transactions_commit` API and requires no extra dependencies. On older Rails versions you need to manually specify the `after_commit_action` gem as a dependency in your Gemfile to use this feature:
276
276
  ```ruby
277
277
  ...
278
278
  gem "after_commit_action"
@@ -15,6 +15,13 @@ module CounterCulture
15
15
  Gem::Requirement.new('>= 7.2.0').satisfied_by?(ActiveRecord.version)
16
16
  end
17
17
 
18
+ # Rails 7.2+ ships `ActiveRecord.after_all_transactions_commit`, which lets
19
+ # `execute_after_commit` defer counter updates natively instead of relying on
20
+ # the `after_commit_action` gem.
21
+ def self.supports_native_after_commit?
22
+ Gem::Requirement.new('>= 7.2.0').satisfied_by?(ActiveRecord.version)
23
+ end
24
+
18
25
  class Configuration
19
26
  attr_reader :use_read_replica
20
27
 
@@ -21,7 +21,10 @@ module CounterCulture
21
21
  @execute_after_commit = options.fetch(:execute_after_commit, false)
22
22
  @include_soft_deleted = options.fetch(:include_soft_deleted, false)
23
23
 
24
- if @execute_after_commit
24
+ # Rails 7.2+ ships `ActiveRecord.after_all_transactions_commit`, which
25
+ # does everything we need the `after_commit_action` gem for. Only fall
26
+ # back to the gem on older Rails versions.
27
+ if @execute_after_commit && !CounterCulture.supports_native_after_commit?
25
28
  begin
26
29
  require 'after_commit_action'
27
30
  rescue LoadError
@@ -390,7 +393,18 @@ module CounterCulture
390
393
  execute_after_commit = @execute_after_commit.is_a?(Proc) ? @execute_after_commit.call : @execute_after_commit
391
394
 
392
395
  if execute_after_commit
393
- obj.execute_after_commit(&block)
396
+ if CounterCulture.supports_native_after_commit?
397
+ # NOTE: `after_all_transactions_commit` waits for *every* open
398
+ # transaction across *all* database connections and skips the block if
399
+ # any of them roll back, whereas `after_commit_action` tied the block to
400
+ # this record's own connection only. The two are equivalent for a
401
+ # single database; they differ only when a record is saved inside
402
+ # transactions that span multiple databases (which Rails itself
403
+ # discourages).
404
+ ActiveRecord.after_all_transactions_commit(&block)
405
+ else
406
+ obj.execute_after_commit(&block)
407
+ end
394
408
  else
395
409
  block.call
396
410
  end
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.13.3'.freeze
2
+ VERSION = '3.14.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.13.3
4
+ version: 3.14.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: 2026-06-25 00:00:00.000000000 Z
11
+ date: 2026-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord