counter_culture 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce78ea0f9a3ad552e5cb8b0e230dbc70fc3fcb51f9f0c21676c3ecca7601569a
4
- data.tar.gz: 840001761832861fbbef2e3d921d553d0ea39c685a8ab16b4096444722bb5d03
3
+ metadata.gz: 749d2a26a921731dd342cddd6d9e479776b26eb3ccd836fb703e47bca4c05b22
4
+ data.tar.gz: f59ff08373a8831c2f96605bf75063b5d50d6f1adecfa0486a53d41a3c9a8b9b
5
5
  SHA512:
6
- metadata.gz: 41e59967d03892c1d0ce48d1c804862bcd0ffb575df9675869fc94fcba13440f8eaf07f4a06b6b5b88a168c79efd06af4a4b88634f8bdc9d8ca0b5c990b0c81f
7
- data.tar.gz: 1e90fa445eb4972dea2c7ce851719e8fa0a095aa2526b177fd1d2ec5ae9de8d85f4bf9d1b3cc1a112a1186f76add7b7d564efab9bb146085fdf1c1011cda5ebf
6
+ metadata.gz: 3a57f1f22ce98c08ccf76552a040445bbcf37f53966bf3abde13f2be2fcb9c4abbf3ea13f8e911ffd536122f161e04cb0a6b62b0a1330435c2568bd8d06c39ac
7
+ data.tar.gz: f29b2abad46f30de69df23e0e02fa0bcb75447fd2dd854cc42dc979efbe9955316984285ae68bfd3033e4e0d8a2d31bc06699a667b2c375306e654ac2eaff8f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.4.0 (July 12, 2023)
2
+
3
+ Improvements:
4
+ - Ability to skip counter culture updates in a block (#371)
5
+
1
6
  ## 3.3.1 (June 26, 2023)
2
7
 
3
8
  Bugfixes:
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
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.3.1'.freeze
2
+ VERSION = '3.4.0'.freeze
3
3
  end
@@ -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.3.1
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-06-26 00:00:00.000000000 Z
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.2
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.