incrdecr_cached_counts 0.5.0 → 0.6.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: 5c0a0f2090aabd3b286436ad4bce2dca587f003cb5c19307be1d7974c84894ab
4
- data.tar.gz: 546850171cb6d859149155acd0a6c3cc4697702306c7e7d7015c6a6e86bc4066
3
+ metadata.gz: 0d5bd60c008ad0b41a08214d9243ebb6278467bb3ca2b5f3314609c5361b6c1a
4
+ data.tar.gz: cea01587597deb81ff143e8383a194238a00e36c2e2529760aec60a83f485b5c
5
5
  SHA512:
6
- metadata.gz: dc5aa5c3e0977528853821aa6d11484f1bfccbb8c435c003ea4c90856cac06933448c52707884dd182a5727f04c701ff5a5bf21d8454b695637a62fd0860ed72
7
- data.tar.gz: 7ce3ec421d5bea4a5f6e1a5a80c341fcb603f8288a13751058afb9ced3aea58ceae75668a42522132d3f3246e5955a60a16ecf80f6b9a1b6d6017a1286e9f9b1
6
+ metadata.gz: a8e9a0efe389831ae4f8d28db0cc23f2b873c705231fed8caa80ee322e84abf0d0998f6f3d777a8e7ce565ce0c2770ab3438322ff50a2921349d3d9e4f81dac6
7
+ data.tar.gz: b8fdd83b366cc6827cf925bfb003a065a2139ab98a103b9cb2ad9daac89f421fd3110328d80e5c6910caa7ce9322c06791c67b3d64caf66c5d030e41cbdd1b35
@@ -1,3 +1,3 @@
1
1
  module CachedCounts
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/cached_counts.rb CHANGED
@@ -159,16 +159,6 @@ module CachedCounts
159
159
  fallback = Rails.cache.read(key)
160
160
  fallback = fallback.value if fallback.is_a?(ActiveSupport::Cache::Entry)
161
161
 
162
- if fallback.nil?
163
- begin
164
- fallback = relation.count
165
- rescue ActiveRecord::StatementInvalid => e
166
- fallback = 0
167
- end
168
-
169
- Rails.cache.write key, fallback, expires_in: options.fetch(:expires_in, 1.week), raw: true
170
- end
171
-
172
162
  -> { fallback }
173
163
  end
174
164
 
@@ -253,13 +243,16 @@ module CachedCounts
253
243
  # Ensure that other reads find something in the cache, but
254
244
  # continue calculating here because the default is likely inaccurate.
255
245
  fallback_value = instance_exec &race_condition_fallback
256
- CachedCounts.logger.warn "Setting #{fallback_value} as race_condition_fallback for #{send(key_method)}"
257
- Rails.cache.write(
258
- send(key_method),
259
- fallback_value.to_i,
260
- expires_in: 30.seconds,
261
- raw: true
262
- )
246
+
247
+ if fallback_value
248
+ CachedCounts.logger.warn "Setting #{fallback_value} as race_condition_fallback for #{send(key_method)}"
249
+ Rails.cache.write(
250
+ send(key_method),
251
+ fallback_value.to_i,
252
+ expires_in: 30.seconds,
253
+ raw: true
254
+ )
255
+ end
263
256
  end
264
257
 
265
258
  relation = instance_exec(&relation_getter)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incrdecr_cached_counts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Judd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails