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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/counter_culture/counter.rb +21 -1
- 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: 75ac99d8d45f3e16859bb04854958dac048a449aa4afe94f12885cefe3a94787
|
|
4
|
+
data.tar.gz: e90d1b87ea3e2d919434dbeea2263fa5556044dc273cab21a6a67b423519c012
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc1196535a528c5f87e39aca06d5e1a3e014f469c8aa3e8f01c56f75a59489c4db25dc9b67168b162ddf9ac24e45c55fe887c10176e76786dea5ffe72603f10b
|
|
7
|
+
data.tar.gz: a949a3856773028e954e00c8ce5ba89ac0e999230c47af3d1b0e312fdef827cbbf0dc71ed91406c6b2b77ba4d194b108f21df8b904f0e09592d2b5ef2a0e25d9
|
data/CHANGELOG.md
CHANGED
|
@@ -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
|
-
|
|
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
|
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.
|
|
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-
|
|
11
|
+
date: 2025-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|