counter_culture 3.3.1 → 3.4.0
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 +12 -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 +4 -3
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/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -190,6 +190,18 @@ Now, the ```Category``` model will keep the counter cache in ```special_count```
|
|
|
190
190
|
|
|
191
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).
|
|
192
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
|
+
|
|
193
205
|
### Totaling instead of counting
|
|
194
206
|
|
|
195
207
|
Instead of keeping a running count, you may want to automatically track a running total.
|
|
@@ -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: 2023-
|
|
11
|
+
date: 2023-07-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -321,6 +321,7 @@ files:
|
|
|
321
321
|
- lib/counter_culture/counter.rb
|
|
322
322
|
- lib/counter_culture/extensions.rb
|
|
323
323
|
- lib/counter_culture/reconciler.rb
|
|
324
|
+
- lib/counter_culture/skip_updates.rb
|
|
324
325
|
- lib/counter_culture/version.rb
|
|
325
326
|
- lib/generators/counter_culture_generator.rb
|
|
326
327
|
- lib/generators/templates/counter_culture_migration.rb.erb
|
|
@@ -343,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
343
344
|
- !ruby/object:Gem::Version
|
|
344
345
|
version: '0'
|
|
345
346
|
requirements: []
|
|
346
|
-
rubygems_version: 3.4.
|
|
347
|
+
rubygems_version: 3.4.10
|
|
347
348
|
signing_key:
|
|
348
349
|
specification_version: 4
|
|
349
350
|
summary: Turbo-charged counter caches for your Rails app.
|