counter_culture 3.13.2 → 3.13.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/README.md +1 -1
- data/lib/counter_culture/reconciler.rb +25 -6
- data/lib/counter_culture/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c24eb92adf8139552bb89de6d5f39f41f1fc46b89a9b23f66309385ab31cb6f
|
|
4
|
+
data.tar.gz: b3ec3a46a8bcaa1520b193a47909d3233c0193958849caac5cbe580acc621316
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd20102f237e5a2a3757567339afb5c60d5ef87e6d97c411a2e51a365749e1e45482a63553d631bf8337cbce997d657c708a34a7bf8a4a7d84b87dfd77d241b8
|
|
7
|
+
data.tar.gz: 533d50714673ce1e209db0e7ebbf29717668783014d3753d15306f6e0705c042a50821602ca948ed1444ec5adc76799c059e5735c5db0f416b6664f4fc414459
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# counter_culture [](https://circleci.com/gh/magnusvk/counter_culture/tree/main)
|
|
2
2
|
|
|
3
3
|
Turbo-charged counter caches for your Rails app. Huge improvements over the Rails standard counter caches:
|
|
4
4
|
|
|
@@ -108,13 +108,15 @@ module CounterCulture
|
|
|
108
108
|
next unless column_name
|
|
109
109
|
|
|
110
110
|
relation_class_table_name = quote_table_name(relation_class.table_name)
|
|
111
|
+
# quote the cache column so reserved-word/quoting-sensitive names work
|
|
112
|
+
quoted_column_name = quote_column_name(column_name)
|
|
111
113
|
|
|
112
114
|
# select join column and count (from above) as well as cache column ('column_name') for later comparison
|
|
113
115
|
counts_query = scope.select(
|
|
114
116
|
"#{primary_key_select}, " \
|
|
115
117
|
"#{association_primary_key_select}, " \
|
|
116
118
|
"#{count_select} AS count, " \
|
|
117
|
-
"MAX(#{relation_class_table_name}.#{
|
|
119
|
+
"MAX(#{relation_class_table_name}.#{quoted_column_name}) AS #{quoted_column_name}"
|
|
118
120
|
)
|
|
119
121
|
|
|
120
122
|
# we need to join together tables until we get back to the table this class itself lives in
|
|
@@ -155,9 +157,20 @@ module CounterCulture
|
|
|
155
157
|
|
|
156
158
|
track_change(record, column_name, count)
|
|
157
159
|
|
|
158
|
-
updates
|
|
159
|
-
#
|
|
160
|
-
updates
|
|
160
|
+
# Build a Hash of column => value updates and let Rails (Arel) qualify
|
|
161
|
+
# and escape the column names and cast/quote the values, consistent with
|
|
162
|
+
# the Arel-based updates used in Counter (see #425). This updates the
|
|
163
|
+
# actual counter.
|
|
164
|
+
updates = { column_name => count }
|
|
165
|
+
|
|
166
|
+
# Set lock_version = lock_version (no-op) to skip Rails auto-increment,
|
|
167
|
+
# just as Counter does (see #429); a Hash update_all would otherwise
|
|
168
|
+
# bump the optimistic locking column.
|
|
169
|
+
if relation_class.locking_enabled?
|
|
170
|
+
lock_column = relation_class.locking_column
|
|
171
|
+
updates[lock_column] = relation_class.arel_table[lock_column]
|
|
172
|
+
end
|
|
173
|
+
|
|
161
174
|
# and here we update the timestamp, if so desired
|
|
162
175
|
if options[:touch]
|
|
163
176
|
current_time = record.send(:current_time_from_proper_timezone)
|
|
@@ -168,13 +181,13 @@ module CounterCulture
|
|
|
168
181
|
timestamp_columns << options[:touch]
|
|
169
182
|
end
|
|
170
183
|
timestamp_columns.each do |timestamp_column|
|
|
171
|
-
updates
|
|
184
|
+
updates[timestamp_column] = current_time
|
|
172
185
|
end
|
|
173
186
|
end
|
|
174
187
|
|
|
175
188
|
with_writing_db_connection do
|
|
176
189
|
conditions = Array.wrap(relation_class.primary_key).map { |key| [key, record.send(key)] }.to_h
|
|
177
|
-
relation_class.where(conditions).distinct(false).update_all(updates
|
|
190
|
+
relation_class.where(conditions).distinct(false).update_all(updates)
|
|
178
191
|
end
|
|
179
192
|
end
|
|
180
193
|
end
|
|
@@ -351,6 +364,12 @@ module CounterCulture
|
|
|
351
364
|
end
|
|
352
365
|
end
|
|
353
366
|
|
|
367
|
+
def quote_column_name(column_name)
|
|
368
|
+
@connection_handler.call do |connection|
|
|
369
|
+
connection.quote_column_name(column_name)
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
354
373
|
def parameterize(string)
|
|
355
374
|
if ACTIVE_RECORD_VERSION < Gem::Version.new("5.0")
|
|
356
375
|
string.parameterize('_')
|