jason-rails 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/client/package.json +1 -1
- data/lib/jason/lua_generator.rb +20 -6
- data/lib/jason/publisher.rb +5 -1
- data/lib/jason/subscription.rb +11 -8
- data/lib/jason/version.rb +1 -1
- 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: 592a7eab8028ae28815abbf0d401d98b2ceabc0009f30713f68795da21adb165
|
4
|
+
data.tar.gz: 315f5088e258dcab9755dc92f4de03f3f2f016cf6698d3619f022c1e7d601e9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a33fdc1d57462a97b7dd571222ff314cc77338e5172fcfc662f3e1fd5f008deed299abcd870900d0b50805944af822b462f6adee46953895499ce49f69df6680
|
7
|
+
data.tar.gz: 8ec1a59761856754f09bb7b6431d3d45d319daf9d4c7f030b8c7c2301c28ab2d0393952c4d7339a4d6310da2689c3cba8c71048deed931e0d3c4b0cf5c2fc2f1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.8.0
|
2
|
+
- Cold cache handling:
|
3
|
+
- Expiry is now set on all cached models of one week
|
4
|
+
- Code now handles case where cached model is missing and repopulates the cache
|
5
|
+
|
6
|
+
## v0.7.5
|
7
|
+
- Fixed JS errors when payloads arrive on websockets after the subscription has been unmounted
|
8
|
+
- Fixed errors during initialization due to calling `cache_all` on a Rails model before it had fully initialized.
|
9
|
+
|
1
10
|
## v0.7.3
|
2
11
|
- Added: Add JasonContext to exports, for use in scenarios where you need to forward the context into some other React reconciler (e.g. `react-three-fiber`)
|
3
12
|
- Fixed: Unneeded `reload` in Publisher resulting in extra database calls
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ An alternative way of thinking about Jason is "what if we applied the Flux/Redux
|
|
21
21
|
Add the gem and the NPM package
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
gem 'jason-rails'
|
24
|
+
gem 'jason-rails', require: 'jason'
|
25
25
|
```
|
26
26
|
|
27
27
|
```bash
|
@@ -180,6 +180,7 @@ Development is primarily driven by the needs of projects we're using Jason in. I
|
|
180
180
|
|
181
181
|
## Publishing a new version
|
182
182
|
- Update `version.rb`
|
183
|
+
- Update CHANGELOG
|
183
184
|
- `gem build`
|
184
185
|
- `gem push`
|
185
186
|
- `npm version [major/minor/patch]`
|
data/client/package.json
CHANGED
data/lib/jason/lua_generator.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
class Jason::LuaGenerator
|
2
2
|
## TODO load these scripts and evalsha
|
3
3
|
def cache_json(model_name, id, payload)
|
4
|
+
expiry = 7*24*60*60 + rand(6*60*60)
|
5
|
+
|
6
|
+
# ensure the content expires first
|
4
7
|
cmd = <<~LUA
|
5
8
|
local gidx = redis.call('INCR', 'jason:gidx')
|
6
|
-
redis.call( '
|
7
|
-
redis.call( '
|
9
|
+
redis.call( 'setex', 'jason:cache:' .. ARGV[1] .. ':' .. ARGV[2] .. ':gidx', #{expiry}, gidx )
|
10
|
+
redis.call( 'setex', 'jason:cache:' .. ARGV[1] .. ':' .. ARGV[2], #{expiry - 60}, ARGV[3] )
|
8
11
|
return gidx
|
9
12
|
LUA
|
10
13
|
|
@@ -15,15 +18,26 @@ class Jason::LuaGenerator
|
|
15
18
|
# If value has changed, return old value and new idx. Otherwise do nothing.
|
16
19
|
cmd = <<~LUA
|
17
20
|
local t = {}
|
18
|
-
local
|
21
|
+
local insts = {}
|
22
|
+
local miss_ids = {}
|
19
23
|
local ids = redis.call('smembers', 'jason:subscriptions:' .. ARGV[2] .. ':ids:' .. ARGV[1])
|
20
24
|
|
21
25
|
for k,id in pairs(ids) do
|
22
|
-
|
26
|
+
local result = redis.call( 'get', 'jason:cache:' .. ARGV[1] .. ':' .. id)
|
27
|
+
if (result == false) then
|
28
|
+
miss_ids[#miss_ids+1] = id
|
29
|
+
else
|
30
|
+
insts[#insts+1] = result
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
if next(miss_ids) == nil then
|
35
|
+
t[#t+1] = insts
|
36
|
+
t[#t+1] = redis.call( 'get', 'jason:subscription:' .. ARGV[2] .. ':' .. ARGV[1] .. ':idx' )
|
37
|
+
else
|
38
|
+
t[#t+1] = miss_ids
|
39
|
+
t[#t+1] = 'missing'
|
40
|
+
end
|
27
41
|
|
28
42
|
return t
|
29
43
|
LUA
|
data/lib/jason/publisher.rb
CHANGED
@@ -124,7 +124,7 @@ module Jason::Publisher
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def jason_cached_value
|
127
|
-
JSON.parse($redis_jason.
|
127
|
+
JSON.parse($redis_jason.get("jason:cache:#{self.class.name.underscore}:#{id}") || '{}')
|
128
128
|
end
|
129
129
|
|
130
130
|
class_methods do
|
@@ -132,6 +132,10 @@ module Jason::Publisher
|
|
132
132
|
all.find_each(&:cache_json)
|
133
133
|
end
|
134
134
|
|
135
|
+
def cache_for(ids)
|
136
|
+
where(id: ids).find_each(&:cache_json)
|
137
|
+
end
|
138
|
+
|
135
139
|
def has_jason?
|
136
140
|
true
|
137
141
|
end
|
data/lib/jason/subscription.rb
CHANGED
@@ -399,16 +399,17 @@ class Jason::Subscription
|
|
399
399
|
end
|
400
400
|
|
401
401
|
def get_for_model(model_name)
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
end
|
407
|
-
instance_jsons = instance_jsons_hash.values
|
408
|
-
else
|
402
|
+
instance_jsons, idx = Jason::LuaGenerator.new.get_payload(model_name, id)
|
403
|
+
if idx == 'missing'
|
404
|
+
# warm cache and then retry
|
405
|
+
model_klass(model_name).cache_for(instance_jsons)
|
409
406
|
instance_jsons, idx = Jason::LuaGenerator.new.get_payload(model_name, id)
|
410
407
|
end
|
411
408
|
|
409
|
+
if instance_jsons.any? { |json| json.blank? }
|
410
|
+
raise Jason::MissingCacheError
|
411
|
+
end
|
412
|
+
|
412
413
|
payload = instance_jsons.map do |instance_json|
|
413
414
|
instance_json ? JSON.parse(instance_json) : {}
|
414
415
|
end
|
@@ -437,7 +438,7 @@ class Jason::Subscription
|
|
437
438
|
|
438
439
|
def add(model_name, instance_id)
|
439
440
|
idx = $redis_jason.incr("jason:subscription:#{id}:#{model_name}:idx")
|
440
|
-
payload = JSON.parse($redis_jason.
|
441
|
+
payload = JSON.parse($redis_jason.get("jason:cache:#{model_name}:#{instance_id}") || '{}')
|
441
442
|
|
442
443
|
payload = {
|
443
444
|
id: instance_id,
|
@@ -479,3 +480,5 @@ class Jason::Subscription
|
|
479
480
|
broadcaster.broadcast(payload)
|
480
481
|
end
|
481
482
|
end
|
483
|
+
|
484
|
+
class Jason::MissingCacheError < StandardError; end
|
data/lib/jason/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jason-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Rees
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|