counter_culture 3.3.0 → 3.4.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 +10 -1
- data/CHANGELOG.md +10 -0
- data/README.md +15 -2
- data/counter_culture.gemspec +1 -1
- data/lib/counter_culture/counter.rb +2 -0
- data/lib/counter_culture/extensions.rb +10 -0
- data/lib/counter_culture/skip_updates.rb +26 -0
- data/lib/counter_culture/version.rb +1 -1
- data/lib/counter_culture.rb +2 -0
- metadata +5 -5
- data/circle.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749d2a26a921731dd342cddd6d9e479776b26eb3ccd836fb703e47bca4c05b22
|
4
|
+
data.tar.gz: f59ff08373a8831c2f96605bf75063b5d50d6f1adecfa0486a53d41a3c9a8b9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a57f1f22ce98c08ccf76552a040445bbcf37f53966bf3abde13f2be2fcb9c4abbf3ea13f8e911ffd536122f161e04cb0a6b62b0a1330435c2568bd8d06c39ac
|
7
|
+
data.tar.gz: f29b2abad46f30de69df23e0e02fa0bcb75447fd2dd854cc42dc979efbe9955316984285ae68bfd3033e4e0d8a2d31bc06699a667b2c375306e654ac2eaff8f7
|
data/.circleci/config.yml
CHANGED
@@ -48,7 +48,7 @@ workflows:
|
|
48
48
|
- test:
|
49
49
|
matrix:
|
50
50
|
parameters:
|
51
|
-
ruby-version: ["2.6", "2.7", "3.0", "3.1"]
|
51
|
+
ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2"]
|
52
52
|
rails-version: ["5.2", "6.0", "6.1", "7.0"]
|
53
53
|
database: ["postgresql", "sqlite3", "mysql2"]
|
54
54
|
exclude:
|
@@ -67,6 +67,15 @@ workflows:
|
|
67
67
|
- ruby-version: "3.1"
|
68
68
|
rails-version: "5.2"
|
69
69
|
database: "sqlite3"
|
70
|
+
- ruby-version: "3.2"
|
71
|
+
rails-version: "5.2"
|
72
|
+
database: "mysql2"
|
73
|
+
- ruby-version: "3.2"
|
74
|
+
rails-version: "5.2"
|
75
|
+
database: "postgresql"
|
76
|
+
- ruby-version: "3.2"
|
77
|
+
rails-version: "5.2"
|
78
|
+
database: "sqlite3"
|
70
79
|
- ruby-version: "3.1"
|
71
80
|
rails-version: "5.2"
|
72
81
|
database: "mysql2"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 3.4.0 (July 12, 2023)
|
2
|
+
|
3
|
+
Improvements:
|
4
|
+
- Ability to skip counter culture updates in a block (#371)
|
5
|
+
|
6
|
+
## 3.3.1 (June 26, 2023)
|
7
|
+
|
8
|
+
Bugfixes:
|
9
|
+
- Read primary key on polymorphic associations if it's explicitly set (#370)
|
10
|
+
|
1
11
|
## 3.3.0 (October 11, 2022)
|
2
12
|
|
3
13
|
Improvements:
|
data/README.md
CHANGED
@@ -7,10 +7,11 @@ 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.6, 2.7 and 3.
|
10
|
+
Tested against Ruby 2.6, 2.7, 3.0, 3.1 and 3.2, 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
|
+
|
14
|
+
```ruby
|
14
15
|
product.categories.size # => will lead to a SELECT COUNT(*) query
|
15
16
|
product.categories_count # => will use counter cache without query
|
16
17
|
```
|
@@ -189,6 +190,18 @@ Now, the ```Category``` model will keep the counter cache in ```special_count```
|
|
189
190
|
|
190
191
|
If you would like to use this with `counter_culture_fix_counts`, make sure to also provide [the `column_names` configuration](#handling-dynamic-column-names).
|
191
192
|
|
193
|
+
### Temporarily skipping counter cache updates
|
194
|
+
|
195
|
+
If you would like to temporarily pause counter_culture, for example in a backfill script, you can do so as follows:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
Review.skip_counter_culture_updates do
|
199
|
+
user.reviews.create!
|
200
|
+
end
|
201
|
+
|
202
|
+
user.reviews_count # => unchanged
|
203
|
+
```
|
204
|
+
|
192
205
|
### Totaling instead of counting
|
193
206
|
|
194
207
|
Instead of keeping a running count, you may want to automatically track a running total.
|
data/counter_culture.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'https://github.com/magnusvk/counter_culture'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.required_ruby_version =
|
16
|
+
spec.required_ruby_version = '>= 2.6'
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -284,6 +284,8 @@ module CounterCulture
|
|
284
284
|
if reflect.options.key?(:polymorphic)
|
285
285
|
raise "can't handle multiple keys with polymorphic associations" unless (relation.is_a?(Symbol) || relation.length == 1)
|
286
286
|
raise "must specify source for polymorphic associations..." unless source
|
287
|
+
|
288
|
+
return reflect.options[:primary_key] if reflect.options.key?(:primary_key)
|
287
289
|
return relation_klass(relation, source: source, was: was).try(:primary_key)
|
288
290
|
end
|
289
291
|
reflect.association_primary_key(klass)
|
@@ -91,6 +91,16 @@ module CounterCulture
|
|
91
91
|
reconciler.changes
|
92
92
|
end.compact
|
93
93
|
end
|
94
|
+
|
95
|
+
def skip_counter_culture_updates
|
96
|
+
return unless block_given?
|
97
|
+
|
98
|
+
counter_culture_updates_was = Thread.current[:skip_counter_culture_updates]
|
99
|
+
Thread.current[:skip_counter_culture_updates] = Array(counter_culture_updates_was) + [self]
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
Thread.current[:skip_counter_culture_updates] = counter_culture_updates_was
|
103
|
+
end
|
94
104
|
end
|
95
105
|
|
96
106
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CounterCulture
|
2
|
+
module SkipUpdates
|
3
|
+
private
|
4
|
+
|
5
|
+
# called by after_create callback
|
6
|
+
def _update_counts_after_create
|
7
|
+
unless Array(Thread.current[:skip_counter_culture_updates]).include?(self.class)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# called by after_destroy callback
|
13
|
+
def _update_counts_after_destroy
|
14
|
+
unless Array(Thread.current[:skip_counter_culture_updates]).include?(self.class)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# called by after_update callback
|
20
|
+
def _update_counts_after_update
|
21
|
+
unless Array(Thread.current[:skip_counter_culture_updates]).include?(self.class)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/counter_culture.rb
CHANGED
@@ -5,6 +5,7 @@ require 'counter_culture/version'
|
|
5
5
|
require 'counter_culture/extensions'
|
6
6
|
require 'counter_culture/counter'
|
7
7
|
require 'counter_culture/reconciler'
|
8
|
+
require 'counter_culture/skip_updates'
|
8
9
|
|
9
10
|
module CounterCulture
|
10
11
|
mattr_accessor :batch_size
|
@@ -19,4 +20,5 @@ end
|
|
19
20
|
# extend ActiveRecord with our own code here
|
20
21
|
ActiveSupport.on_load(:active_record) do
|
21
22
|
include CounterCulture::Extensions
|
23
|
+
include CounterCulture::SkipUpdates
|
22
24
|
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.4.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: 2023-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -312,7 +312,6 @@ files:
|
|
312
312
|
- LICENSE.txt
|
313
313
|
- README.md
|
314
314
|
- Rakefile
|
315
|
-
- circle.yml
|
316
315
|
- counter_culture.gemspec
|
317
316
|
- gemfiles/rails_5.2.gemfile
|
318
317
|
- gemfiles/rails_6.0.gemfile
|
@@ -322,6 +321,7 @@ files:
|
|
322
321
|
- lib/counter_culture/counter.rb
|
323
322
|
- lib/counter_culture/extensions.rb
|
324
323
|
- lib/counter_culture/reconciler.rb
|
324
|
+
- lib/counter_culture/skip_updates.rb
|
325
325
|
- lib/counter_culture/version.rb
|
326
326
|
- lib/generators/counter_culture_generator.rb
|
327
327
|
- lib/generators/templates/counter_culture_migration.rb.erb
|
@@ -337,14 +337,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
337
337
|
requirements:
|
338
338
|
- - ">="
|
339
339
|
- !ruby/object:Gem::Version
|
340
|
-
version: 2.
|
340
|
+
version: '2.6'
|
341
341
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
342
342
|
requirements:
|
343
343
|
- - ">="
|
344
344
|
- !ruby/object:Gem::Version
|
345
345
|
version: '0'
|
346
346
|
requirements: []
|
347
|
-
rubygems_version: 3.
|
347
|
+
rubygems_version: 3.4.10
|
348
348
|
signing_key:
|
349
349
|
specification_version: 4
|
350
350
|
summary: Turbo-charged counter caches for your Rails app.
|