jason-rails 0.6.0 → 0.6.1

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: 453e1a0d649445d973de2e3adf27f88f91c5bf983e65b3c2d993f090816db72b
4
- data.tar.gz: ec2600988c60bcb6f661b8835cd3bcb7d3a4b740749ab0f21109e9b6a513b4ca
3
+ metadata.gz: a641c2277ccd7336d71cb79cd3f65710ebb0078db5cef102441d9c3fc2e6102d
4
+ data.tar.gz: 467d4fff10d1f4c9a1ee847e409d4b8cc3ab8f8a7a0e93e9404fe275a35a3e47
5
5
  SHA512:
6
- metadata.gz: cc2ba8529669a1fe4c48d2ee2ba595a7e3ae907a0d10234f12d68d797de63177143187c5c3767cf32ab35bd053c3c9f3bfa14461f8b6be71d8df437e3e997c7d
7
- data.tar.gz: c93e0002f3a7e2379ed29483b6a8323b4b492a319ccc4f9948f0638c47e62a9eeb8b416fad2bbe2cc6b5c13f11a103eab462b7a35f5a36145037981e49c99cc6
6
+ metadata.gz: 606d1919bfe6c512e98a565619662b23f76f639da7ce55defafef7ced5b2e0112af8e4d61e63aa00b6335803faaaa6b863d621a114259ca5998c574d4ed5d59b
7
+ data.tar.gz: a4f1c02c5c8c6a14fc6aa128b55ebc25ba54e2293561dd335dd87bb75b49e32df7af9434186f247efee6b81e16dae59e02d56a87f696ef8b217a01f167ac9f8c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jason-rails (0.5.1)
4
+ jason-rails (0.6.0)
5
5
  connection_pool (>= 2.2.3)
6
6
  jsondiff
7
7
  rails (>= 5)
data/README.md CHANGED
@@ -142,6 +142,7 @@ Development is primarily driven by the needs of projects we're using Jason in. I
142
142
  - Failure handling - rolling back local state in case of an error on the server
143
143
  - Authorization - more thorough authorization integration, with utility functions for common authorizations. Allowing authorization of access to particular fields such as restricting the fields of a user that are publicly broadcast.
144
144
  - Utilities for "Draft editing" - both storing client-side copies of model trees which can be committed or discarded, as well as persisting a shadow copy to the database (to allow resumable editing, or possibly collaborative editing features)
145
+ - Benchmark and migrate if necessary ConnectionPool::Wrapper vs ConnectionPool
145
146
 
146
147
  ## Development
147
148
 
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
data/lib/jason.rb CHANGED
@@ -30,20 +30,47 @@ module Jason
30
30
  self.pusher_region = 'eu'
31
31
  self.pusher_channel_prefix = 'jason'
32
32
 
33
- # add default values of more config vars here
33
+ def self.init
34
+ # Check if the schema has changed since last time app was started. If so, do some work to ensure cache contains the correct data
35
+ got_lock = $redis_jason.set('jason:schema:lock', nx: true, ex: 3600) # Basic lock mechanism for multi-process environments
36
+ return if !got_lock
37
+
38
+ previous_schema = JSON.parse($redis_jason.get('jason:last_schema') || '{}')
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
+ current_schema.each do |model, config|
42
+ if config != previous_schema[model]
43
+ puts "Config changed for #{model}"
44
+ puts "Old config was #{previous_schema[model]}"
45
+ puts "New config is #{config}"
46
+ puts "Rebuilding cache for #{model}"
47
+ model.classify.constantize.cache_all
48
+ puts "Done"
49
+ end
50
+ end
51
+
52
+ $redis_jason.set('jason:last_schema', current_schema.to_json)
53
+ ensure
54
+ $redis_jason.del('jason:schema:lock')
55
+
56
+ previous_config = 'test'
57
+ end
58
+
34
59
 
35
60
  # this function maps the vars from your app into your engine
36
61
  def self.setup(&block)
37
62
  yield self
38
- end
39
63
 
40
- $redis_jason = self.redis || ::ConnectionPool::Wrapper.new(size: 5, timeout: 3) { ::Redis.new(url: ENV['REDIS_URL']) }
64
+ $redis_jason = self.redis || ::ConnectionPool::Wrapper.new(size: 5, timeout: 3) { ::Redis.new(url: ENV['REDIS_URL']) }
41
65
 
42
- if ![:action_cable, :pusher].include?(self.transport_service)
43
- raise "Unknown transport service '#{self.transport_service}' specified"
44
- end
66
+ if ![:action_cable, :pusher].include?(self.transport_service)
67
+ raise "Unknown transport service '#{self.transport_service}' specified"
68
+ end
69
+
70
+ if self.transport_service == :pusher && self.pusher.blank?
71
+ raise "Pusher specified as transport service but no Pusher client provided. Please configure with config.pusher = Pusher::Client.new(...)"
72
+ end
45
73
 
46
- if self.transport_service == :pusher && self.pusher.blank?
47
- raise "Pusher specified as transport service but no Pusher client provided. Please configure with config.pusher = Pusher::Client.new(...)"
74
+ init
48
75
  end
49
76
  end
@@ -91,6 +91,10 @@ module Jason::Publisher
91
91
  Jason::Subscription.for_instance(self.class.name.underscore, id)
92
92
  end
93
93
 
94
+ def jason_cached_value
95
+ JSON.parse($redis_jason.hget("jason:cache:#{self.class.name.underscore}", id) || '{}')
96
+ end
97
+
94
98
  class_methods do
95
99
  def cache_all
96
100
  all.each(&:cache_json)
@@ -362,8 +362,6 @@ class Jason::Subscription
362
362
  instance_jsons, idx = Jason::LuaGenerator.new.get_payload(model_name, id)
363
363
  end
364
364
 
365
- return if instance_jsons.blank?
366
-
367
365
  payload = instance_jsons.map do |instance_json|
368
366
  instance_json ? JSON.parse(instance_json) : {}
369
367
  end
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
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.0
4
+ version: 0.6.1
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-13 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails