counter_culture 1.9.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +12 -0
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -3
- data/lib/counter_culture/extensions.rb +1 -1
- data/lib/counter_culture/reconciler.rb +14 -2
- data/spec/counter_culture_spec.rb +57 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f0d12b75377e5baffc9364982bfd8d08f2f5530
|
4
|
+
data.tar.gz: 21a22f582dd41bc8a6e7d9cc85a70757f5acb982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0a5bba782c586130d2436ae029e147d848a3fd740ecf2060e45a43e8df8775401dedd7b1df23643a71420a7c5ecbab63f4a47359c770263cfc5997110d7b608
|
7
|
+
data.tar.gz: f83999e34478258e389cb0d893194b0839104c5f7fd3adcef11b2833bfae1b5de72b087fc0d71e8528aca3479b52b9664cdf43bddf8c12f67e5fcd3125e4851d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -272,6 +272,18 @@ Product.counter_culture_fix_counts batch_size: 100
|
|
272
272
|
|
273
273
|
```counter_culture_fix_counts``` is optimized to minimize the number of queries and runs very quickly.
|
274
274
|
|
275
|
+
Similarly to `counter_culture`, it is possible to update the records' timestamps, when fixing counts. If you would like to update the default timestamp field, pass `touch: true` option:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
Product.counter_culture_fix_counts touch: true
|
279
|
+
```
|
280
|
+
|
281
|
+
If you have specified a custom timestamps column, pass its name as the value for the `touch` option:
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
Product.counter_culture_fix_counts touch: category_count_changed
|
285
|
+
```
|
286
|
+
|
275
287
|
#### Handling dynamic column names
|
276
288
|
|
277
289
|
Manually populating counter caches with dynamic column names requires additional configuration:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.10.0
|
data/counter_culture.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: counter_culture 1.
|
5
|
+
# stub: counter_culture 1.10.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "counter_culture"
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.10.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Magnus von Koeller"]
|
14
|
-
s.date = "2018-04-
|
14
|
+
s.date = "2018-04-20"
|
15
15
|
s.description = "counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback."
|
16
16
|
s.email = "magnus@vonkoeller.de"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -70,7 +70,7 @@ module CounterCulture
|
|
70
70
|
next if options[:exclude] && options[:exclude].include?(counter.relation)
|
71
71
|
next if options[:only] && !options[:only].include?(counter.relation)
|
72
72
|
|
73
|
-
reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported, :batch_size))
|
73
|
+
reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported, :batch_size, :touch))
|
74
74
|
reconciler.reconcile!
|
75
75
|
reconciler.changes
|
76
76
|
end.compact
|
@@ -114,8 +114,20 @@ module CounterCulture
|
|
114
114
|
|
115
115
|
track_change(record, column_name, count)
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
updates = []
|
118
|
+
# this updates the actual counter
|
119
|
+
updates << "#{column_name} = #{count}"
|
120
|
+
# and here we update the timestamp, if so desired
|
121
|
+
if options[:touch]
|
122
|
+
current_time = record.send(:current_time_from_proper_timezone)
|
123
|
+
timestamp_columns = record.send(:timestamp_attributes_for_update_in_model)
|
124
|
+
timestamp_columns << options[:touch] if options[:touch] != true
|
125
|
+
timestamp_columns.each do |timestamp_column|
|
126
|
+
updates << "#{timestamp_column} = '#{current_time.to_formatted_s(:db)}'"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
relation_class.where(relation_class.primary_key => record.send(relation_class.primary_key)).update_all(updates.join(', '))
|
119
131
|
end
|
120
132
|
end
|
121
133
|
end
|
@@ -948,6 +948,63 @@ describe "CounterCulture" do
|
|
948
948
|
expect(Review.counter_culture_fix_counts(skip_unsupported: true)).to eq([{ entity: 'User', id: user1.id, what: 'reviews_count', right: 1, wrong: 2 }])
|
949
949
|
end
|
950
950
|
|
951
|
+
it 'should update the timestamp when fixing counts with `touch: true`' do
|
952
|
+
product = Product.create
|
953
|
+
review = Review.create product: product
|
954
|
+
|
955
|
+
product.update_column :reviews_count, 2
|
956
|
+
|
957
|
+
product.reload
|
958
|
+
|
959
|
+
old_product_updated_at = product.updated_at
|
960
|
+
|
961
|
+
Timecop.travel(1.second.from_now) do
|
962
|
+
Review.counter_culture_fix_counts(skip_unsupported: true, only: :product, touch: true)
|
963
|
+
|
964
|
+
product.reload
|
965
|
+
|
966
|
+
expect(product.updated_at).to be > old_product_updated_at
|
967
|
+
end
|
968
|
+
end
|
969
|
+
|
970
|
+
it 'should not update the timestamp when fixing counts without `touch: true`' do
|
971
|
+
product = Product.create
|
972
|
+
review = Review.create product: product
|
973
|
+
|
974
|
+
product.update_column :reviews_count, 2
|
975
|
+
|
976
|
+
product.reload
|
977
|
+
|
978
|
+
old_product_updated_at = product.updated_at
|
979
|
+
|
980
|
+
Timecop.travel(2.second.from_now) do
|
981
|
+
Review.counter_culture_fix_counts(skip_unsupported: true, only: :product)
|
982
|
+
|
983
|
+
product.reload
|
984
|
+
|
985
|
+
expect(product.updated_at).to eq old_product_updated_at
|
986
|
+
end
|
987
|
+
end
|
988
|
+
|
989
|
+
it 'should update the timestamp of a custom column when fixing counts with touch: rexiews_updated_at' do
|
990
|
+
product = Product.create
|
991
|
+
review = Review.create product: product
|
992
|
+
|
993
|
+
product.update_column :rexiews_count, 2
|
994
|
+
|
995
|
+
product.reload
|
996
|
+
|
997
|
+
old_rexiews_updated_at = product.rexiews_updated_at
|
998
|
+
|
999
|
+
Timecop.travel(1.second.from_now) do
|
1000
|
+
Review.counter_culture_fix_counts(skip_unsupported: true, touch: :rexiews_updated_at)
|
1001
|
+
|
1002
|
+
product.reload
|
1003
|
+
|
1004
|
+
expect(product.rexiews_updated_at).to be > old_rexiews_updated_at
|
1005
|
+
end
|
1006
|
+
end
|
1007
|
+
|
951
1008
|
it "should fix a simple counter cache correctly" do
|
952
1009
|
user = User.create
|
953
1010
|
product = Product.create
|
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: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus von Koeller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_commit_action
|