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 +4 -4
- data/lib/cached_counts/version.rb +1 -1
- data/lib/cached_counts.rb +10 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d5bd60c008ad0b41a08214d9243ebb6278467bb3ca2b5f3314609c5361b6c1a
|
4
|
+
data.tar.gz: cea01587597deb81ff143e8383a194238a00e36c2e2529760aec60a83f485b5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e9a0efe389831ae4f8d28db0cc23f2b873c705231fed8caa80ee322e84abf0d0998f6f3d777a8e7ce565ce0c2770ab3438322ff50a2921349d3d9e4f81dac6
|
7
|
+
data.tar.gz: b8fdd83b366cc6827cf925bfb003a065a2139ab98a103b9cb2ad9daac89f421fd3110328d80e5c6910caa7ce9322c06791c67b3d64caf66c5d030e41cbdd1b35
|
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
|
-
|
257
|
-
|
258
|
-
send(key_method)
|
259
|
-
|
260
|
-
|
261
|
-
|
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.
|
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:
|
11
|
+
date: 2022-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|