jason-rails 0.6.4 → 0.6.5

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: 2788ecafe67bc475346d83681912063b1081610e06b685405d4f3b332a665695
4
- data.tar.gz: 6647cc3a7815a914b98a9477330c32a642fec64c809aa4195fa5c192a4b4b003
3
+ metadata.gz: 3dcf3cd2febb358e030ebe12ca382b463a8ca97dcdbb228d9a4354f2687b2cd1
4
+ data.tar.gz: fb385f90db387e2e4dfc1ce8016b1d800ac3ba6b78e3a54f59a1ec17d670aaef
5
5
  SHA512:
6
- metadata.gz: cf1b1ed464f9ef46cd5b3aa2dd7e8ebb982a3d6d3ebe68a3f92f2ad8b5ab31ea8476817fd16666346d358e9d5a635b4af792bba16e41105eefb7a789082567f1
7
- data.tar.gz: a06afb2c5db05447d7eda5a6f17020a14fd1d486b50f17e14c155738e7166534a52c418f5463742c0956102d744429198ee0101569cef156366586eee3e7c058
6
+ metadata.gz: 17ff6a77e7076e887bc2730ae32607d5c7afcd272dbe535f66259a758867296a759580be3f4385bd878fd908d22e883b0047fbd0bee0134f443457422edf1975
7
+ data.tar.gz: 398111401a126b189398baff186284e11f580e653af6391be7a0576c9d1c4832ec6915400071fd66e4819b676deeeae52d35b75fe9499b480c73c5c88c135cfb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jason-rails (0.6.0)
4
+ jason-rails (0.6.4)
5
5
  connection_pool (>= 2.2.3)
6
6
  jsondiff
7
7
  rails (>= 5)
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
data/lib/jason.rb CHANGED
@@ -37,7 +37,6 @@ module Jason
37
37
 
38
38
  previous_schema = JSON.parse($redis_jason.get('jason:last_schema') || '{}')
39
39
  current_schema = Jason.schema.deep_stringify_keys.deep_transform_values { |v| v.is_a?(Symbol) ? v.to_s : v }
40
- pp current_schema
41
40
  current_schema.each do |model, config|
42
41
  if config != previous_schema[model]
43
42
  puts "Config changed for #{model}"
@@ -33,7 +33,8 @@ class Jason::GraphHelper
33
33
  end
34
34
 
35
35
  # Add and remove edges, return graph before and after
36
- def apply_update(add: nil, remove: nil)
36
+ # Enforce means make the graph contain only the add_edges
37
+ def apply_update(add: nil, remove: nil, enforce: false)
37
38
  add_edges = []
38
39
  remove_edges = []
39
40
 
@@ -48,11 +49,21 @@ class Jason::GraphHelper
48
49
  remove_edges += build_edges(edge_set[:model_names], edge_set[:instance_ids], include_root: false)
49
50
  end
50
51
  end
51
- diff_edges_from_graph(add_edges: add_edges, remove_edges: remove_edges)
52
+
53
+ diff_edges_from_graph(add_edges: add_edges, remove_edges: remove_edges, enforce: enforce)
52
54
  end
53
55
 
54
- def diff_edges_from_graph(add_edges: [], remove_edges: [])
55
- old_edges, new_edges = Jason::LuaGenerator.new.update_set_with_diff("jason:subscriptions:#{id}:graph", add_edges.flatten, remove_edges.flatten)
56
+ def diff_edges_from_graph(add_edges: [], remove_edges: [], enforce: false)
57
+ if enforce
58
+ old_edges = $redis_jason.multi do |r|
59
+ r.smembers("jason:subscriptions:#{id}:graph")
60
+ r.del("jason:subscriptions:#{id}:graph")
61
+ r.sadd("jason:subscriptions:#{id}:graph", add_edges) if add_edges.present?
62
+ end[0]
63
+ new_edges = add_edges
64
+ else
65
+ old_edges, new_edges = Jason::LuaGenerator.new.update_set_with_diff("jason:subscriptions:#{id}:graph", add_edges.flatten, remove_edges.flatten)
66
+ end
56
67
 
57
68
  old_graph = build_graph_from_edges(old_edges)
58
69
  new_graph = build_graph_from_edges(new_edges)
@@ -269,7 +269,8 @@ class Jason::Subscription
269
269
 
270
270
  # Build the tree
271
271
  id_changeset = graph_helper.apply_update({
272
- add: [edge_set]
272
+ add: [edge_set],
273
+ enforce: enforce
273
274
  })
274
275
  apply_id_changeset(id_changeset)
275
276
  end
@@ -320,7 +321,7 @@ class Jason::Subscription
320
321
  $redis_jason.hset("jason:consumers", consumer_id, Time.now.utc)
321
322
 
322
323
  if before_consumer_count == 0
323
- set_ids_for_sub_models
324
+ set_ids_for_sub_models(enforce: true)
324
325
  end
325
326
  end
326
327
 
@@ -375,6 +376,20 @@ class Jason::Subscription
375
376
  }
376
377
  end
377
378
 
379
+ # To be used as a fallback when some corruption of the subscription has taken place
380
+ def reset!(hard: false)
381
+ # Remove subscription state
382
+ if hard
383
+ clear_all_ids
384
+ $redis_jason.del("jason:subscriptions:#{id}:graph")
385
+ end
386
+
387
+ set_ids_for_sub_models(enforce: true)
388
+ includes_helper.all_models.each do |model_name|
389
+ broadcaster.broadcast(get_for_model(model_name))
390
+ end
391
+ end
392
+
378
393
  def add(model_name, instance_id)
379
394
  idx = $redis_jason.incr("jason:subscription:#{id}:#{model_name}:idx")
380
395
  payload = JSON.parse($redis_jason.hget("jason:cache:#{model_name}", instance_id) || '{}')
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
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.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Rees
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-17 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails