svelte-on-rails 23.2.5 → 23.3.0
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 +4 -4
- data/lib/svelte_on_rails/lib/utils.rb +20 -0
- data/lib/svelte_on_rails/lib/view_helper_support.rb +7 -3
- data/lib/tasks/cache_module.rb +150 -0
- data/lib/tasks/cache_tasks.rake +17 -48
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f09ad4a3bf1a1c6e122b757ebcd40cd2f74d3f7e23ce0cd7428068fad2c5c46
|
|
4
|
+
data.tar.gz: e579fcbdae349b2ed2286d0b3d52020651e5b84dad12920a13e7fe9dd80fb03d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd3c39b27b49af39d86d59959d14c930685adc13b0cc2eef3d173063816905bafe2d44c84f647aaa2f495b7866a485fc9053564e0a28ae234a7395a4142f3fdf
|
|
7
|
+
data.tar.gz: 062a962c55dbc2736fe9f78c4b5357f93e44a1dfd9bd933b75c96ad6f0bbbc23ee3aba871e7054cd92583ed5a444e96535c9bdc85a5662a8e97614d3b1b4b4b6
|
|
@@ -96,10 +96,30 @@ module SvelteOnRails
|
|
|
96
96
|
file_basename: file_basename,
|
|
97
97
|
name: file_basename.camelcase,
|
|
98
98
|
vite_path: vite_path,
|
|
99
|
+
cache_key_path: (component_cache_key_path(path) if path),
|
|
99
100
|
failed_attempts: (@attempts unless path)
|
|
100
101
|
}
|
|
101
102
|
end
|
|
102
103
|
|
|
104
|
+
def self.component_cache_key_path(path)
|
|
105
|
+
conf = SvelteOnRails::Configuration.instance
|
|
106
|
+
aliases = conf.configs[:aliases]&.stringify_keys || {}
|
|
107
|
+
|
|
108
|
+
key_path = path.to_s.delete_suffix(".svelte")
|
|
109
|
+
|
|
110
|
+
aliases.each do |alias_name, alias_path|
|
|
111
|
+
normalized_alias_path = alias_path.to_s.delete_suffix("/")
|
|
112
|
+
next unless key_path.start_with?("#{normalized_alias_path}/")
|
|
113
|
+
|
|
114
|
+
key_path = "#{alias_name}/#{key_path.delete_prefix("#{normalized_alias_path}/")}"
|
|
115
|
+
break
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
key_path
|
|
119
|
+
.delete_prefix("app/")
|
|
120
|
+
.tr("/", "-")
|
|
121
|
+
end
|
|
122
|
+
|
|
103
123
|
def self.manifest_file_mtime
|
|
104
124
|
cnf = SvelteOnRails::Configuration.instance
|
|
105
125
|
if File.exist?(cnf.manifest_json_path)
|
|
@@ -336,14 +336,18 @@ module SvelteOnRails
|
|
|
336
336
|
|
|
337
337
|
def cache_key_fresh
|
|
338
338
|
@cache_key = begin
|
|
339
|
-
|
|
339
|
+
paths = component_paths
|
|
340
|
+
fingerprint = (@conf.watch_changes? ? @conf.fingerprint(paths[:path], debug?, paths[:name]) : '')
|
|
341
|
+
cache_key_path = paths[:cache_key_path]
|
|
342
|
+
visible_cache_key_path = cache_key_path.gsub("-_", "-")
|
|
340
343
|
|
|
341
|
-
cache_key_raw =
|
|
344
|
+
cache_key_raw = cache_key_path +
|
|
345
|
+
@options.to_s +
|
|
342
346
|
@cached_props.to_s +
|
|
343
347
|
fingerprint +
|
|
344
348
|
@html_options.to_s
|
|
345
349
|
|
|
346
|
-
"#{@conf.redis_namespace}#{
|
|
350
|
+
"#{@conf.redis_namespace}#{visible_cache_key_path}:#{Digest::XXH64.hexdigest(cache_key_raw)}"
|
|
347
351
|
end
|
|
348
352
|
end
|
|
349
353
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
module SvelteOnRails
|
|
2
|
+
module Cache
|
|
3
|
+
module_function
|
|
4
|
+
|
|
5
|
+
def redis_entries(silent: false)
|
|
6
|
+
conf = SvelteOnRails::Configuration.instance
|
|
7
|
+
redis = conf.redis_instance
|
|
8
|
+
namespace = conf.redis_namespace
|
|
9
|
+
|
|
10
|
+
unless redis
|
|
11
|
+
warn "svelte_on_rails:show_cache — no redis_instance configured, nothing to show."
|
|
12
|
+
return []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
pattern = "#{namespace}*"
|
|
16
|
+
|
|
17
|
+
puts "Scanning Redis for keys matching «#{pattern}» ..." unless silent
|
|
18
|
+
|
|
19
|
+
entries = [] # [{ key:, bytes:, ttl:, type: }]
|
|
20
|
+
cursor = "0"
|
|
21
|
+
|
|
22
|
+
loop do
|
|
23
|
+
cursor, keys = redis.scan(cursor, match: pattern)
|
|
24
|
+
|
|
25
|
+
if keys.any?
|
|
26
|
+
# Pipeline MEMORY USAGE / TTL / TYPE for the whole batch.
|
|
27
|
+
results = redis.pipelined do |p|
|
|
28
|
+
keys.each do |k|
|
|
29
|
+
p.call(["MEMORY", "USAGE", k])
|
|
30
|
+
p.ttl(k)
|
|
31
|
+
p.type(k)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
keys.each_with_index do |k, i|
|
|
36
|
+
bytes = results[i * 3]
|
|
37
|
+
ttl = results[i * 3 + 1]
|
|
38
|
+
type = results[i * 3 + 2]
|
|
39
|
+
entries << { key: k, bytes: bytes.to_i, ttl: ttl.to_i, type: type }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
break if cursor == "0"
|
|
44
|
+
rescue => e
|
|
45
|
+
warn "svelte_on_rails:show_cache — error during scan: #{e.class}: #{e.message}"
|
|
46
|
+
break
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if entries.empty?
|
|
50
|
+
puts "No keys found under «#{pattern}»." unless silent
|
|
51
|
+
return []
|
|
52
|
+
end
|
|
53
|
+
entries
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def print_entries_table(entries)
|
|
57
|
+
entries.sort_by! { |e| -e[:bytes] }
|
|
58
|
+
|
|
59
|
+
key_w = [entries.map { |e| e[:key].length }.max, 3].max
|
|
60
|
+
size_w = [entries.map { |e| human_bytes(e[:bytes]).length }.max, 4].max
|
|
61
|
+
ttl_w = [entries.map { |e| ttl_str(e[:ttl]).length }.max, 3].max
|
|
62
|
+
type_w = [entries.map { |e| e[:type].to_s.length }.max, 4].max
|
|
63
|
+
|
|
64
|
+
header = format("%-#{key_w}s %#{size_w}s %#{ttl_w}s %-#{type_w}s", "KEY", "SIZE", "TTL", "TYPE")
|
|
65
|
+
puts header
|
|
66
|
+
puts "-" * header.length
|
|
67
|
+
|
|
68
|
+
entries.each do |e|
|
|
69
|
+
puts format(
|
|
70
|
+
"%-#{key_w}s %#{size_w}s %#{ttl_w}s %-#{type_w}s",
|
|
71
|
+
e[:key], human_bytes(e[:bytes]), ttl_str(e[:ttl]), e[:type]
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
total_bytes = entries.sum { |e| e[:bytes] }
|
|
76
|
+
puts "-" * header.length
|
|
77
|
+
puts "Total: #{entries.size} key(s), #{human_bytes(total_bytes)} in RAM"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def print_summary_table(entries)
|
|
81
|
+
summary_entries = summarized_entries(entries)
|
|
82
|
+
|
|
83
|
+
key_w = [summary_entries.map { |e| e[:key].length }.max, 3].max
|
|
84
|
+
count_w = [summary_entries.map { |e| e[:count].to_s.length }.max, 5].max
|
|
85
|
+
size_w = [summary_entries.map { |e| human_bytes(e[:bytes]).length }.max, 4].max
|
|
86
|
+
|
|
87
|
+
header = format("%-#{key_w}s %#{count_w}s %#{size_w}s", "KEY", "COUNT", "SIZE")
|
|
88
|
+
puts header
|
|
89
|
+
puts "-" * header.length
|
|
90
|
+
|
|
91
|
+
summary_entries.each do |e|
|
|
92
|
+
puts format(
|
|
93
|
+
"%-#{key_w}s %#{count_w}d %#{size_w}s",
|
|
94
|
+
e[:key], e[:count], human_bytes(e[:bytes])
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
total_bytes = entries.sum { |e| e[:bytes] }
|
|
99
|
+
puts "-" * header.length
|
|
100
|
+
puts "Total: #{entries.size} key(s), #{summary_entries.size} group(s), #{human_bytes(total_bytes)} in RAM"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def summarized_entries(entries)
|
|
104
|
+
entries
|
|
105
|
+
.group_by { |entry| summary_key(entry[:key]) }
|
|
106
|
+
.map do |key, grouped_entries|
|
|
107
|
+
{
|
|
108
|
+
key: key,
|
|
109
|
+
count: grouped_entries.size,
|
|
110
|
+
bytes: grouped_entries.sum { |entry| entry[:bytes] }
|
|
111
|
+
}
|
|
112
|
+
end
|
|
113
|
+
.sort_by { |entry| -entry[:bytes] }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def summary_key(key)
|
|
117
|
+
prefix, separator, suffix = key.rpartition(":")
|
|
118
|
+
return key if separator.empty?
|
|
119
|
+
return prefix if suffix.match?(/\A[0-9a-f]{16,}\z/i)
|
|
120
|
+
|
|
121
|
+
key
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def human_bytes(n)
|
|
125
|
+
return "0 B" if n.nil? || n <= 0
|
|
126
|
+
|
|
127
|
+
units = %w[B KB MB GB TB]
|
|
128
|
+
i = (Math.log(n) / Math.log(1024)).floor
|
|
129
|
+
i = units.length - 1 if i >= units.length
|
|
130
|
+
format("%.2f %s", n.to_f / (1024 ** i), units[i])
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def ttl_str(ttl)
|
|
134
|
+
case ttl
|
|
135
|
+
when -2 then "gone"
|
|
136
|
+
when -1 then "∞"
|
|
137
|
+
else
|
|
138
|
+
if ttl >= 86_400
|
|
139
|
+
"#{(ttl / 86_400.0).round(1)}d"
|
|
140
|
+
elsif ttl >= 3_600
|
|
141
|
+
"#{(ttl / 3_600.0).round(1)}h"
|
|
142
|
+
elsif ttl >= 60
|
|
143
|
+
"#{(ttl / 60.0).round(1)}m"
|
|
144
|
+
else
|
|
145
|
+
"#{ttl}s"
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
data/lib/tasks/cache_tasks.rake
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require_relative "./cache_module"
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
namespace :svelte_on_rails do
|
|
2
5
|
namespace :cache do
|
|
3
6
|
|
|
@@ -49,36 +52,28 @@ namespace :svelte_on_rails do
|
|
|
49
52
|
|
|
50
53
|
desc "Show all svelte-on-rails Redis keys with their memory footprint (scoped to redis_namespace). Env: LIMIT=n, SORT=size|key, PATTERN=extra-glob"
|
|
51
54
|
task show: :environment do
|
|
52
|
-
|
|
53
|
-
_entries = SvelteOnRails::Cache.redis_entries(silent: true)
|
|
55
|
+
entries = SvelteOnRails::Cache.redis_entries(silent: true)
|
|
54
56
|
cnf = SvelteOnRails::Configuration.instance
|
|
55
57
|
|
|
56
|
-
if
|
|
58
|
+
if entries.empty?
|
|
57
59
|
puts "No keys found for redis namespace «#{cnf.redis_namespace}»."
|
|
58
60
|
exit 0
|
|
59
61
|
end
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
key_w = [_entries.map { |e| e[:key].length }.max, 3].max
|
|
64
|
-
size_w = [_entries.map { |e| human_bytes(e[:bytes]).length }.max, 4].max
|
|
65
|
-
ttl_w = [_entries.map { |e| ttl_str(e[:ttl]).length }.max, 3].max
|
|
66
|
-
type_w = [_entries.map { |e| e[:type].to_s.length }.max, 4].max
|
|
63
|
+
SvelteOnRails::Cache.print_entries_table(entries)
|
|
64
|
+
end
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
desc "Show summarized svelte-on-rails Redis cache memory usage grouped by cache key prefix"
|
|
67
|
+
task summary: :environment do
|
|
68
|
+
entries = SvelteOnRails::Cache.redis_entries(silent: true)
|
|
69
|
+
cnf = SvelteOnRails::Configuration.instance
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
puts
|
|
74
|
-
|
|
75
|
-
e[:key], human_bytes(e[:bytes]), ttl_str(e[:ttl]), e[:type]
|
|
76
|
-
)
|
|
71
|
+
if entries.empty?
|
|
72
|
+
puts "No keys found for redis namespace «#{cnf.redis_namespace}»."
|
|
73
|
+
exit 0
|
|
77
74
|
end
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
puts "-" * header.length
|
|
81
|
-
puts "Total: #{_entries.size} key(s), #{human_bytes(total_bytes)} in RAM"
|
|
76
|
+
SvelteOnRails::Cache.print_summary_table(entries)
|
|
82
77
|
end
|
|
83
78
|
|
|
84
79
|
desc "Show contents of cached keys"
|
|
@@ -89,7 +84,7 @@ namespace :svelte_on_rails do
|
|
|
89
84
|
entries.each do |e|
|
|
90
85
|
puts
|
|
91
86
|
puts '='*120
|
|
92
|
-
puts "#{e[:key]} (#{human_bytes(e[:bytes])})"
|
|
87
|
+
puts "#{e[:key]} (#{SvelteOnRails::Cache.human_bytes(e[:bytes])})"
|
|
93
88
|
puts '-'*120
|
|
94
89
|
puts SvelteOnRails::Configuration.instance.redis_instance.get(e[:key])
|
|
95
90
|
puts
|
|
@@ -108,37 +103,11 @@ namespace :svelte_on_rails do
|
|
|
108
103
|
nok = Nokogiri::HTML(ht)
|
|
109
104
|
|
|
110
105
|
puts '='*120
|
|
111
|
-
puts "#{e[:key]} (#{human_bytes(e[:bytes])})"
|
|
106
|
+
puts "#{e[:key]} (#{SvelteOnRails::Cache.human_bytes(e[:bytes])})"
|
|
112
107
|
puts '-'*120
|
|
113
108
|
puts nok.at_css('.svelte-component')&.inner_html
|
|
114
109
|
end
|
|
115
110
|
|
|
116
111
|
end
|
|
117
112
|
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# Helpers used by svelte_on_rails:show_cache
|
|
121
|
-
def human_bytes(n)
|
|
122
|
-
return "0 B" if n.nil? || n <= 0
|
|
123
|
-
units = %w[B KB MB GB TB]
|
|
124
|
-
i = (Math.log(n) / Math.log(1024)).floor
|
|
125
|
-
i = units.length - 1 if i >= units.length
|
|
126
|
-
format("%.2f %s", n.to_f / (1024 ** i), units[i])
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def ttl_str(ttl)
|
|
130
|
-
case ttl
|
|
131
|
-
when -2 then "gone"
|
|
132
|
-
when -1 then "∞"
|
|
133
|
-
else
|
|
134
|
-
if ttl >= 86_400 then
|
|
135
|
-
"#{(ttl / 86_400.0).round(1)}d"
|
|
136
|
-
elsif ttl >= 3_600 then
|
|
137
|
-
"#{(ttl / 3_600.0).round(1)}h"
|
|
138
|
-
elsif ttl >= 60 then
|
|
139
|
-
"#{(ttl / 60.0).round(1)}m"
|
|
140
|
-
else
|
|
141
|
-
"#{ttl}s"
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
113
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: svelte-on-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 23.
|
|
4
|
+
version: 23.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: railties
|
|
@@ -101,6 +101,7 @@ files:
|
|
|
101
101
|
- lib/svelte_on_rails/ssr_client.rb
|
|
102
102
|
- lib/svelte_on_rails/turbo_stream.rb
|
|
103
103
|
- lib/svelte_on_rails/view_helpers.rb
|
|
104
|
+
- lib/tasks/cache_module.rb
|
|
104
105
|
- lib/tasks/cache_tasks.rake
|
|
105
106
|
- lib/tasks/general_tasks.rake
|
|
106
107
|
- lib/tasks/ssr_client_tasks.rake
|