counter_culture 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +66 -0
- data/Appraisals +1 -22
- data/CHANGELOG.md +9 -0
- data/README.md +14 -3
- data/counter_culture.gemspec +1 -1
- data/gemfiles/rails_5.2.gemfile +0 -3
- data/gemfiles/rails_6.0.gemfile +0 -3
- data/gemfiles/rails_6.1.gemfile +0 -3
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/lib/counter_culture/counter.rb +4 -2
- data/lib/counter_culture/extensions.rb +3 -2
- data/lib/counter_culture/reconciler.rb +2 -2
- data/lib/counter_culture/version.rb +1 -1
- metadata +8 -7
- data/.travis.yml +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95534ee62aca302b549c2dcac07fc297169c388686330d44fd7113e4ef2b20bc
|
4
|
+
data.tar.gz: b19462c370aca6769529a3f1485f6bf5cbaba9b51b4df8edc3f7f4fcd01dac40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6f3b86aff4915f42227de7303a1b8dfef7e6be9de77574b0887c44022393a8d4135329c1a538ba7e0fb0595cd27c021905a401303727169b90ac4ec3d891120
|
7
|
+
data.tar.gz: 7453a54d51964e9ee157ee6a9a7d6a4977c0f21b4e6261859558b83b92c29a03e4619428d88b18988f08c27db8f2afce0fecf32edb1156c3550b76aa8ba4388a
|
@@ -0,0 +1,66 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
orbs:
|
4
|
+
ruby: circleci/ruby@1.4
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
parameters:
|
9
|
+
ruby-version:
|
10
|
+
type: string
|
11
|
+
rails-version:
|
12
|
+
type: string
|
13
|
+
database:
|
14
|
+
type: string
|
15
|
+
docker:
|
16
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
17
|
+
- image: cimg/postgres:14.1
|
18
|
+
- image: cimg/mysql:8.0
|
19
|
+
steps:
|
20
|
+
- checkout
|
21
|
+
- run:
|
22
|
+
name: bundle update
|
23
|
+
command: BUNDLE_GEMFILE=gemfiles/rails_<< parameters.rails-version >>.gemfile bundle update
|
24
|
+
- run:
|
25
|
+
name: install dockerize
|
26
|
+
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
|
27
|
+
environment:
|
28
|
+
DOCKERIZE_VERSION: v0.3.0
|
29
|
+
- run:
|
30
|
+
name: Wait for Postgres
|
31
|
+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
|
32
|
+
- run:
|
33
|
+
name: Wait for MySQL
|
34
|
+
command: dockerize -wait tcp://localhost:3306 -timeout 1m
|
35
|
+
- run:
|
36
|
+
name: rspec
|
37
|
+
command: DB=<< parameters.database >> rspec spec
|
38
|
+
|
39
|
+
workflows:
|
40
|
+
test:
|
41
|
+
jobs:
|
42
|
+
- test:
|
43
|
+
matrix:
|
44
|
+
parameters:
|
45
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
46
|
+
rails-version: ["5.2", "6.0", "6.1", "7.0"]
|
47
|
+
database: ["postgresql", "sqlite3", "mysql2"]
|
48
|
+
exclude:
|
49
|
+
- ruby-version: "3.0"
|
50
|
+
rails-version: "5.2"
|
51
|
+
database: "postgresql"
|
52
|
+
- ruby-version: "3.0"
|
53
|
+
rails-version: "5.2"
|
54
|
+
database: "sqlite3"
|
55
|
+
- ruby-version: "3.0"
|
56
|
+
rails-version: "5.2"
|
57
|
+
database: "mysql2"
|
58
|
+
- ruby-version: "2.6"
|
59
|
+
rails-version: "7.0"
|
60
|
+
database: "postgresql"
|
61
|
+
- ruby-version: "2.6"
|
62
|
+
rails-version: "7.0"
|
63
|
+
database: "sqlite3"
|
64
|
+
- ruby-version: "2.6"
|
65
|
+
rails-version: "7.0"
|
66
|
+
database: "mysql2"
|
data/Appraisals
CHANGED
@@ -2,30 +2,9 @@
|
|
2
2
|
5.2
|
3
3
|
6.0
|
4
4
|
6.1
|
5
|
+
7.0
|
5
6
|
].each do |rails_version|
|
6
|
-
gem_rails_version = Gem::Version.new(rails_version)
|
7
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0') &&
|
8
|
-
gem_rails_version >= Gem::Version.new('6.0.0.beta')
|
9
|
-
|
10
|
-
# Rails 6 requires Ruby >= 2.5
|
11
|
-
next
|
12
|
-
end
|
13
7
|
appraise "rails-#{rails_version}" do
|
14
8
|
gem 'rails', "~> #{rails_version}.0"
|
15
|
-
|
16
|
-
if gem_rails_version < Gem::Version.new('5.0')
|
17
|
-
gem 'pg', '~> 0.15'
|
18
|
-
else
|
19
|
-
gem 'pg'
|
20
|
-
end
|
21
|
-
gem 'mysql2'
|
22
|
-
if gem_rails_version < Gem::Version.new('5.2')
|
23
|
-
gem 'sqlite3', '~> 1.3.0'
|
24
|
-
else
|
25
|
-
gem 'sqlite3'
|
26
|
-
end
|
27
|
-
if gem_rails_version < Gem::Version.new('5.0')
|
28
|
-
gem 'bigdecimal', '~> 1.3.5'
|
29
|
-
end
|
30
9
|
end
|
31
10
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 3.2.0 (January 24, 2022)
|
2
|
+
|
3
|
+
Improvements:
|
4
|
+
- Allow specifiying `polymorphic_classes` to avoid a potentially expensive
|
5
|
+
`DISTINCT` query when calling `counter_culture_fix_counts` (#336)
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
- Fix primary key name for enumerable relations (#337)
|
9
|
+
|
1
10
|
## 3.1.0 (November 29, 2021)
|
2
11
|
|
3
12
|
Improvements:
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# counter_culture [![Build Status](https://
|
1
|
+
# counter_culture [![Build Status](https://circleci.com/gh/magnusvk/counter_culture/tree/master.svg?style=svg)](https://circleci.com/gh/magnusvk/counter_culture/tree/master)
|
2
2
|
|
3
3
|
Turbo-charged counter caches for your Rails app. Huge improvements over the Rails standard counter caches:
|
4
4
|
|
@@ -7,7 +7,7 @@ Turbo-charged counter caches for your Rails app. Huge improvements over the Rail
|
|
7
7
|
* Supports dynamic column names, making it possible to split up the counter cache for different types of objects
|
8
8
|
* Can keep a running count, or a running total
|
9
9
|
|
10
|
-
Tested against Ruby 2.
|
10
|
+
Tested against Ruby 2.6, 2.7 and 3.0, and against the latest patch releases of Rails 5.2, 6.0, 6.1 and 7.0.
|
11
11
|
|
12
12
|
Please note that -- unlike Rails' built-in counter-caches -- counter_culture does not currently change the behavior of the `.size` method on ActiveRecord associations. If you want to avoid a database query and read the cached value, please use the attribute name containing the counter cache directly.
|
13
13
|
```
|
@@ -378,7 +378,7 @@ end
|
|
378
378
|
|
379
379
|
You can specify a scope instead of a where condition string for `column_names`. We recommend
|
380
380
|
providing a Proc that returns a hash instead of directly providing a hash: If you were to directly
|
381
|
-
provide a scope this would load your schema cache on startup which will break things like
|
381
|
+
provide a scope this would load your schema cache on startup which will break things like
|
382
382
|
`rake db:migrate`.
|
383
383
|
|
384
384
|
```ruby
|
@@ -459,6 +459,17 @@ end
|
|
459
459
|
|
460
460
|
counter_culture now supports polymorphic associations of one level only.
|
461
461
|
|
462
|
+
To discover which models need to be updated via `counter_culture_fix_counts`,
|
463
|
+
counter_culture performs a `DISTINCT` query on the polymorphic relationship.
|
464
|
+
This query can be expensive so we therefore offer the option
|
465
|
+
(`polymorphic_classes`) to specify the models' counts that should be corrected:
|
466
|
+
|
467
|
+
```ruby
|
468
|
+
Image.counter_culture_fix_counts(polymorphic_classes: Product)
|
469
|
+
# or
|
470
|
+
Image.counter_culture_fix_counts(polymorphic_classes: [Product, Employee])
|
471
|
+
```
|
472
|
+
|
462
473
|
## Contributing to counter_culture
|
463
474
|
|
464
475
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/counter_culture.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'after_commit_action'
|
39
39
|
spec.add_development_dependency 'rails', '>= 4.2'
|
40
40
|
spec.add_development_dependency 'rake', '>= 10.0'
|
41
|
-
spec.add_development_dependency 'rdoc',
|
41
|
+
spec.add_development_dependency 'rdoc', ">= 6.3.1"
|
42
42
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
43
|
spec.add_development_dependency 'rspec-extra-formatters'
|
44
44
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
data/gemfiles/rails_5.2.gemfile
CHANGED
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
@@ -163,8 +163,9 @@ module CounterCulture
|
|
163
163
|
# pass true to get the past value, false or nothing to get the
|
164
164
|
# current value
|
165
165
|
def foreign_key_value(obj, relation, was = false)
|
166
|
+
original_relation = relation
|
166
167
|
relation = relation.is_a?(Enumerable) ? relation.dup : [relation]
|
167
|
-
|
168
|
+
|
168
169
|
if was
|
169
170
|
first = relation.shift
|
170
171
|
foreign_key_value = attribute_was(obj, relation_foreign_key(first))
|
@@ -180,7 +181,8 @@ module CounterCulture
|
|
180
181
|
while !value.nil? && relation.size > 0
|
181
182
|
value = value.send(relation.shift)
|
182
183
|
end
|
183
|
-
|
184
|
+
|
185
|
+
return value.try(relation_primary_key(original_relation, source: obj, was: was).try(:to_sym))
|
184
186
|
end
|
185
187
|
|
186
188
|
# gets the reflect object on the given relation
|
@@ -71,7 +71,8 @@ module CounterCulture
|
|
71
71
|
# options:
|
72
72
|
# { :exclude => list of relations to skip when fixing counts,
|
73
73
|
# :only => only these relations will have their counts fixed,
|
74
|
-
# :column_name => only this column will have its count fixed
|
74
|
+
# :column_name => only this column will have its count fixed
|
75
|
+
# :polymorphic_classes => specify the class(es) to update in polymorphic associations }
|
75
76
|
# returns: a list of fixed record as an array of hashes of the form:
|
76
77
|
# { :entity => which model the count was fixed on,
|
77
78
|
# :id => the id of the model that had the incorrect count,
|
@@ -91,7 +92,7 @@ module CounterCulture
|
|
91
92
|
next if options[:exclude] && options[:exclude].include?(counter.relation)
|
92
93
|
next if options[:only] && !options[:only].include?(counter.relation)
|
93
94
|
|
94
|
-
reconciler_options = %i(batch_size column_name finish skip_unsupported start touch verbose where)
|
95
|
+
reconciler_options = %i(batch_size column_name finish skip_unsupported start touch verbose where polymorphic_classes)
|
95
96
|
|
96
97
|
reconciler = CounterCulture::Reconciler.new(counter, options.slice(*reconciler_options))
|
97
98
|
reconciler.reconcile!
|
@@ -28,7 +28,7 @@ module CounterCulture
|
|
28
28
|
raise "Fixing counter caches is not supported when :delta_magnitude is a Proc; you may skip this relation with :skip_unsupported => true" if delta_magnitude.is_a?(Proc)
|
29
29
|
end
|
30
30
|
|
31
|
-
associated_model_classes.each do |associated_model_class|
|
31
|
+
Array(associated_model_classes).each do |associated_model_class|
|
32
32
|
Reconciliation.new(counter, changes, options, associated_model_class).perform
|
33
33
|
end
|
34
34
|
|
@@ -39,7 +39,7 @@ module CounterCulture
|
|
39
39
|
|
40
40
|
def associated_model_classes
|
41
41
|
if polymorphic?
|
42
|
-
polymorphic_associated_model_classes
|
42
|
+
options[:polymorphic_classes].presence || polymorphic_associated_model_classes
|
43
43
|
else
|
44
44
|
[associated_model_class]
|
45
45
|
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.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -182,16 +182,16 @@ dependencies:
|
|
182
182
|
name: rdoc
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 6.3.1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 6.3.1
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: rspec
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -302,10 +302,10 @@ extra_rdoc_files:
|
|
302
302
|
- LICENSE.txt
|
303
303
|
- README.md
|
304
304
|
files:
|
305
|
+
- ".circleci/config.yml"
|
305
306
|
- ".document"
|
306
307
|
- ".gitignore"
|
307
308
|
- ".rspec"
|
308
|
-
- ".travis.yml"
|
309
309
|
- Appraisals
|
310
310
|
- CHANGELOG.md
|
311
311
|
- Gemfile
|
@@ -317,6 +317,7 @@ files:
|
|
317
317
|
- gemfiles/rails_5.2.gemfile
|
318
318
|
- gemfiles/rails_6.0.gemfile
|
319
319
|
- gemfiles/rails_6.1.gemfile
|
320
|
+
- gemfiles/rails_7.0.gemfile
|
320
321
|
- lib/counter_culture.rb
|
321
322
|
- lib/counter_culture/counter.rb
|
322
323
|
- lib/counter_culture/extensions.rb
|
data/.travis.yml
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
dist: focal
|
2
|
-
language: ruby
|
3
|
-
cache:
|
4
|
-
directories:
|
5
|
-
- ~/.rvm/gems
|
6
|
-
services:
|
7
|
-
- postgresql
|
8
|
-
- mysql
|
9
|
-
branches:
|
10
|
-
only:
|
11
|
-
- master
|
12
|
-
addons:
|
13
|
-
postgresql: '12'
|
14
|
-
apt:
|
15
|
-
packages:
|
16
|
-
- postgresql-12
|
17
|
-
- postgresql-client-12
|
18
|
-
rvm:
|
19
|
-
- "2.6.8"
|
20
|
-
- "2.7.4"
|
21
|
-
- "3.0.2"
|
22
|
-
gemfile:
|
23
|
-
- gemfiles/rails_5.2.gemfile
|
24
|
-
- gemfiles/rails_6.0.gemfile
|
25
|
-
- gemfiles/rails_6.1.gemfile
|
26
|
-
matrix:
|
27
|
-
exclude:
|
28
|
-
- rvm: "3.0.2"
|
29
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
30
|
-
env:
|
31
|
-
global:
|
32
|
-
- PGUSER=postgres
|
33
|
-
- PGPORT=5432
|
34
|
-
- PGHOST=localhost
|
35
|
-
jobs:
|
36
|
-
- DB=postgresql
|
37
|
-
- DB=sqlite3
|
38
|
-
- DB=mysql2
|
39
|
-
before_install:
|
40
|
-
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
|
41
|
-
- sudo service postgresql restart
|
42
|
-
- sleep 1
|
43
|
-
- postgres --version
|
44
|
-
- if [ "$BUNDLE_GEMFILE" = "$PWD/gemfiles/rails_4.2.gemfile" ]; then gem install bundler -v '1.17.3'; else gem install bundler -v '> 2'; fi
|
45
|
-
install:
|
46
|
-
- if [ "$BUNDLE_GEMFILE" = "$PWD/gemfiles/rails_4.2.gemfile" ]; then bundle _1.17.3_ update; else bundle update; fi
|
47
|
-
before_script:
|
48
|
-
- psql -c 'create database counter_culture_test;' -U postgres
|
49
|
-
- mysql -e 'CREATE DATABASE counter_culture_test;'
|
50
|
-
script: TRAVIS=true bundle exec rake spec
|