svelte-on-rails 22.4.0 → 22.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4e1180e9510fa0b8592b0b17be5ae1f75348124861184022648f2ec6b96865d
4
- data.tar.gz: 737ff843db6d9fe9ae04d34fd24b214089368d2b34357ac0e64a14ff90c13d52
3
+ metadata.gz: 58df2a12a11fd0781c7e00d95418b4313d18effd284f913ed9d8d2ac79191adf
4
+ data.tar.gz: eb08daf8b9bf7f60531fd3090890462a873c1f14a688a15e766f714ff36e38a5
5
5
  SHA512:
6
- metadata.gz: 769b3c284cdddd35fb86895a29a6ae3a7bce52f501cb689856c1d166892fd360a264eafe274f2cc41944ec57d1a044d25c2c3a1934149ce9e0d1afb972f4501a
7
- data.tar.gz: 2d067a4983fb063fc1e38a1a68e235050d405dad829bea0727ceed9a6d0a35752909d2ae2aba99177e73af21ef01e0cd848d51c30612838ea48fda5163c95c90
6
+ metadata.gz: 93853048bfc3ffdd8d874f94d012e555e9247f0bcf42db4850d1bfe2a9e450dc278f4ee4b85fef5ab721c61794e02f30e8041dd2a067bb4a2337c0966a100784
7
+ data.tar.gz: 4d504b58c5f9a32726ab1047dd8c1d14b37548c33642d13e5f37d2626bc9da7a3ee5e7cf85f004eca4aec8363f2de34e086fbc13773edc12afc1ce63f23680b7
@@ -42,11 +42,8 @@ module SvelteOnRails
42
42
 
43
43
  # DEFAULTS
44
44
 
45
- if @configs[:redis_cache_store]
46
- store = @configs[:redis_cache_store]
47
- @redis_namespace = store[:namespace]
48
- end
49
- @redis_namespace ||= "#{app_name}:svelte-on-rails:#{Rails.env rescue 'no-env'}"
45
+ rd = @configs[:redis_cache_store] && @configs[:redis_cache_store][:namespace]
46
+ @redis_namespace ||= "#{rd || app_name}:svelte-on-rails:#{Rails.env rescue 'no-env'}"
50
47
  @configs[:skip_ssr_header] ||= 'X-Turbo-Request-ID'
51
48
  if defined? Redis
52
49
  @redis_instance = Redis.new(url: redis_cache_store[:url])
@@ -182,7 +179,8 @@ module SvelteOnRails
182
179
 
183
180
  def redis_cache_store_configs
184
181
  if defined?(Rails.application) && Rails.application.config.cache_store.is_a?(Array) && Rails.application.config.cache_store.first == :redis_cache_store
185
- { redis_cache_store: Rails.application.config.cache_store.second.deep_symbolize_keys }
182
+ rc = Rails.application.config.cache_store.second.deep_symbolize_keys
183
+ { redis_cache_store: rc.slice(:url, :namespace) }
186
184
  else
187
185
  {}
188
186
  end
@@ -352,6 +352,7 @@ module SvelteOnRails
352
352
  end
353
353
 
354
354
  def redis_expiration_seconds
355
+ # this accepts integer or ActiveSupport::Duration
355
356
  ex = @options[:cache_expires_in] || conf.configs[:cache_expires_in] || 3.days
356
357
  ex.to_i
357
358
  end
@@ -60,10 +60,7 @@ namespace :svelte_on_rails do
60
60
  next
61
61
  end
62
62
 
63
- extra = ENV["PATTERN"].to_s.strip
64
- pattern = extra.empty? ? "#{namespace}:*" : "#{namespace}:*#{extra}*"
65
- limit = ENV["LIMIT"].to_s =~ /\A\d+\z/ ? ENV["LIMIT"].to_i : nil
66
- sort_by = %w[size key].include?(ENV["SORT"]) ? ENV["SORT"] : "size"
63
+ pattern = "#{namespace}:*"
67
64
 
68
65
  puts "Scanning Redis for keys matching «#{pattern}» ..."
69
66
 
@@ -71,7 +68,7 @@ namespace :svelte_on_rails do
71
68
  cursor = "0"
72
69
 
73
70
  loop do
74
- cursor, keys = redis.scan(cursor, match: pattern, count: 500)
71
+ cursor, keys = redis.scan(cursor, match: pattern)
75
72
 
76
73
  if keys.any?
77
74
  # Pipeline MEMORY USAGE / TTL / TYPE for the whole batch.
@@ -102,19 +99,18 @@ namespace :svelte_on_rails do
102
99
  next
103
100
  end
104
101
 
105
- entries.sort_by! { |e| sort_by == "size" ? -e[:bytes] : e[:key] }
106
- shown = limit ? entries.first(limit) : entries
102
+ entries.sort_by! { |e| -e[:bytes] }
107
103
 
108
- key_w = [shown.map { |e| e[:key].length }.max, 3].max
109
- size_w = [shown.map { |e| human_bytes(e[:bytes]).length }.max, 4].max
110
- ttl_w = [shown.map { |e| ttl_str(e[:ttl]).length }.max, 3].max
111
- type_w = [shown.map { |e| e[:type].to_s.length }.max, 4].max
104
+ key_w = [entries.map { |e| e[:key].length }.max, 3].max
105
+ size_w = [entries.map { |e| human_bytes(e[:bytes]).length }.max, 4].max
106
+ ttl_w = [entries.map { |e| ttl_str(e[:ttl]).length }.max, 3].max
107
+ type_w = [entries.map { |e| e[:type].to_s.length }.max, 4].max
112
108
 
113
109
  header = format("%-#{key_w}s %#{size_w}s %#{ttl_w}s %-#{type_w}s", "KEY", "SIZE", "TTL", "TYPE")
114
110
  puts header
115
111
  puts "-" * header.length
116
112
 
117
- shown.each do |e|
113
+ entries.each do |e|
118
114
  puts format(
119
115
  "%-#{key_w}s %#{size_w}s %#{ttl_w}s %-#{type_w}s",
120
116
  e[:key], human_bytes(e[:bytes]), ttl_str(e[:ttl]), e[:type]
@@ -123,8 +119,7 @@ namespace :svelte_on_rails do
123
119
 
124
120
  total_bytes = entries.sum { |e| e[:bytes] }
125
121
  puts "-" * header.length
126
- puts "Total: #{entries.size} key(s), #{human_bytes(total_bytes)} in RAM" \
127
- "#{limit && entries.size > limit ? " (showing top #{limit} by #{sort_by})" : ""}"
122
+ puts "Total: #{entries.size} key(s), #{human_bytes(total_bytes)} in RAM"
128
123
  end
129
124
  end
130
125
  end
@@ -13,6 +13,21 @@ namespace :svelte_on_rails do
13
13
  ppid = (ppid_file.exist? ? File.read(ppid_file).chomp : nil)
14
14
  server_helpers = SvelteOnRails::SsrServerHelpers.new
15
15
  socket_path = server_helpers.socket_path(ppid: ppid)
16
+
17
+ unless File.socket?(socket_path)
18
+ puts "*" * 80
19
+ puts "ERROR: socket_path does not exist or is not a socket: #{socket_path}"
20
+ puts "Do you have set RAILS_ENV correctly?"
21
+ puts "*" * 80
22
+ end
23
+
24
+ unless ppid_file.exist?
25
+ puts "*" * 80
26
+ puts "ERROR: PPID File does not exist: #{ppid_file}"
27
+ puts "Is the app running?"
28
+ puts "*" * 80
29
+ end
30
+
16
31
  curl_installed = system('which curl > /dev/null 2>&1')
17
32
  if curl_installed
18
33
  curl_cmd = "curl --unix-socket #{socket_path} http://localhost"
@@ -20,12 +35,10 @@ namespace :svelte_on_rails do
20
35
  srv_details = (JSON.parse(stdout) rescue {})
21
36
  end
22
37
 
23
- env_check = rails_env_check(socket_path)
24
-
25
38
  puts
26
39
  puts '=' * line_width
27
40
  puts "Svelte on Rails SSR Server Status:"
28
- puts " Rails env: #{Rails.env.upcase}"
41
+ puts " Rails env: #{Rails.env}"
29
42
  if srv_details['uptime']
30
43
  puts " Uptime: #{srv_details['uptime'].round(0)}sec"
31
44
  else
@@ -40,14 +53,8 @@ namespace :svelte_on_rails do
40
53
  puts label('SSR Server version') + configs.npm_package_version_test.to_s
41
54
  puts
42
55
  puts 'Rails instance'
43
- if !server_helpers.ssr_server_ppid_file.exist?
44
- puts label('Process.ppid') + "#{server_helpers.ssr_server_ppid_file} not found, rails seems not to run or the SsrServer is not initialized yet."
45
- elsif env_check == :clearly_correct
46
- puts label('Process.ppid') + ppid.to_s
47
- puts label('Socket') + socket_path.to_s
48
- else
49
- puts 'Rails env could not be determinated, compared to the socket path, so, no socket path could be determined.'
50
- end
56
+ puts label('Process.ppid') + ppid.to_s
57
+ puts label('Socket') + socket_path.to_s
51
58
  puts
52
59
  puts '=' * line_width
53
60
  puts
@@ -67,72 +74,28 @@ namespace :svelte_on_rails do
67
74
  puts " • kill #{srv_details['pid']}" if srv_details['pid']
68
75
  end
69
76
  puts
70
- if env_check == :clearly_correct
71
- puts '=' * line_width
72
- puts
73
- puts 'NODE INSTANCE INFO:'
74
- puts ' (output of the above mentioned curl command)'
75
- puts
76
- puts '-' * line_width
77
- if curl_installed
78
- stdout, stderr, status = Open3.capture3(curl_cmd)
79
- if status.success?
80
- puts stdout
81
- else
82
- puts "curl exited with status #{status.exitstatus}"
83
- puts stderr unless stderr.to_s.strip.empty?
84
- end
77
+
78
+ puts '=' * line_width
79
+ puts
80
+ puts 'NODE INSTANCE INFO:'
81
+ puts ' (output of the above mentioned curl command)'
82
+ puts
83
+ puts '-' * line_width
84
+ if curl_installed
85
+ stdout, stderr, status = Open3.capture3(curl_cmd)
86
+ if status.success?
87
+ puts stdout
85
88
  else
86
- puts "curl is not installed on this machine, skipping execution."
89
+ puts "curl exited with status #{status.exitstatus}"
90
+ puts stderr unless stderr.to_s.strip.empty?
87
91
  end
88
- puts
89
- puts '=' * line_width
90
- puts
91
- end
92
-
93
- end
94
-
95
- def rails_env_check(socket_path)
96
-
97
- line_width = 100
98
-
99
- envs = guessed_rails_envs(socket_path.dirname)
100
-
101
- if envs == [Rails.env]
102
-
103
- :clearly_correct
104
-
105
- elsif envs.empty?
106
-
107
- puts
108
- puts '*' * line_width
109
- puts "WARNING: This Rails app seems not to run."
110
- puts '*' * line_width
111
- puts
112
- :possible_correct
113
-
114
- elsif envs.include?(Rails.env)
115
-
116
- puts
117
- puts '*' * line_width
118
- puts "INFO: Based on the socket paths #{socket_path.dirname},"
119
- puts "this Rails app may run in #{envs.join(' or ')}."
120
- puts "You are running as #{Rails.env} (Rails.env) which may be right."
121
- puts '*' * line_width
122
- puts
123
- :possible_correct
124
-
125
92
  else
126
-
127
- puts
128
- puts '*' * line_width
129
- puts "WARNING: You are running as #{Rails.env} (Rails.env)"
130
- puts "But the rails app seems to run in #{envs.join(' or ')}"
131
- puts '*' * line_width
132
- puts
133
- :possible_wrong
134
-
93
+ puts "curl is not installed on this machine, skipping execution."
135
94
  end
95
+ puts
96
+ puts '=' * line_width
97
+ puts
98
+
136
99
  end
137
100
 
138
101
  def label(msg)
@@ -140,21 +103,6 @@ namespace :svelte_on_rails do
140
103
  " #{msg}:"[0..20] + (msg.length > 22 ? ':' : '') + ' ' * (20 - l)
141
104
  end
142
105
 
143
- def guessed_rails_envs(dir)
144
- envs_dir = Rails.root.join('config', 'environments')
145
- return [] unless File.directory?(envs_dir) && File.directory?(dir)
146
-
147
- possible_envs = Dir.children(envs_dir)
148
- .select { |f| f.end_with?('.rb') }
149
- .map { |f| File.basename(f, '.rb') }
150
-
151
- entries = Dir.children(dir)
152
-
153
- possible_envs.select do |env|
154
- entries.any? { |entry| entry.include?("-#{env}-") }
155
- end
156
- end
157
-
158
106
  end
159
107
 
160
108
  Rake::Task["assets:precompile"].enhance ["svelte_on_rails:precompile"]
@@ -55,8 +55,9 @@ use_caching: false
55
55
  # this is the default for the #svelte view-helper.
56
56
  # When set to true, the redis gem is required.
57
57
 
58
- cache_expires_in: 3.days
58
+ #cache_expires_in: 4.days
59
59
  # ttl for cache keys
60
+ # can be overridden by view-helper options
60
61
  # default: 3.days
61
62
 
62
63
  debug: true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 22.4.0
4
+ version: 22.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair