counter_culture 3.11.2 → 3.11.3

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: c568fc84225757b834a008eb60dbadfe5dea148078c855fe76a2b5711b0c5b1e
4
- data.tar.gz: 3abc94f197b60fb6778eadb98ad402e6b961155c492970111b85bbf1bd171237
3
+ metadata.gz: 75ac99d8d45f3e16859bb04854958dac048a449aa4afe94f12885cefe3a94787
4
+ data.tar.gz: e90d1b87ea3e2d919434dbeea2263fa5556044dc273cab21a6a67b423519c012
5
5
  SHA512:
6
- metadata.gz: adfd25e90ca300e1d6bc19296b343a8fbd9a272076e48591dddc513ffa4173dff10ef2d26cec6bd08bdfbc372ccf1b94e97cee7d7827205523efe0278d1bffea
7
- data.tar.gz: 733126919913da347057de9c81cbbdf7b4b45e9ea1bbbecad12586a06432801e37b1c8833078cc93ce11fdc0ad3b201c5484822dcebc708f970d2106c022d35b
6
+ metadata.gz: dc1196535a528c5f87e39aca06d5e1a3e014f469c8aa3e8f01c56f75a59489c4db25dc9b67168b162ddf9ac24e45c55fe887c10176e76786dea5ffe72603f10b
7
+ data.tar.gz: a949a3856773028e954e00c8ce5ba89ac0e999230c47af3d1b0e312fdef827cbbf0dc71ed91406c6b2b77ba4d194b108f21df8b904f0e09592d2b5ef2a0e25d9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.11.3 (October 22, 2025)
2
+
3
+ Bugfixes:
4
+ - Fix in-memory counter updates for conditional counters when condition changes (#420)
5
+
1
6
  ## 3.11.2 (July 10, 2025)
2
7
 
3
8
  Bugfixes:
@@ -150,7 +150,27 @@ module CounterCulture
150
150
  execute_now_or_after_commit(obj) do
151
151
  conditions = primary_key_conditions(primary_key, id_to_change)
152
152
  klass.where(conditions).update_all updates.join(', ')
153
- unless options[:was]
153
+ # Determine if we should update the in-memory counter on the associated object.
154
+ # When updating the old counter (was: true), we need to carefully consider two scenarios:
155
+ # 1) The belongs_to relation changed (e.g., moving a child from parent A to parent B):
156
+ # In this case, obj.association now points to parent B, but we're decrementing parent A's
157
+ # counter. We should NOT update the in-memory counter because it would incorrectly
158
+ # modify parent B's cached value.
159
+ # 2) A conditional counter's condition changed (e.g., condition: true → false):
160
+ # In this case, obj.association still points to the same parent, but the counter column
161
+ # name changed (e.g., from 'conditional_count' to nil). We SHOULD update the in-memory
162
+ # counter so the parent object reflects the decremented value without requiring a reload.
163
+ # We distinguish these cases by comparing foreign keys: if the current and previous foreign
164
+ # keys are identical, we're in scenario 2 and should update the in-memory counter.
165
+ should_update_counter = if options[:was]
166
+ current_fk = foreign_key_value(obj, relation, false)
167
+ previous_fk = foreign_key_value(obj, relation, true)
168
+ current_fk == previous_fk && current_fk.present?
169
+ else
170
+ true
171
+ end
172
+
173
+ if should_update_counter
154
174
  assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
155
175
  end
156
176
  end
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.11.2'.freeze
2
+ VERSION = '3.11.3'.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.11.2
4
+ version: 3.11.3
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: 2025-07-10 00:00:00.000000000 Z
11
+ date: 2025-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord