forest_admin_rpc_agent 1.24.9 → 1.24.10
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9fa17e49cf27d2ea01774033fb039ecd0f2187edbc849afe877e82f89320b1c
|
|
4
|
+
data.tar.gz: 9f902d097fe0e06e53211c9bbcaa0b61517749e3159dbb3053daafab864f5536
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62277e517d79e82886e0c17bfd22d72e864ec19a81221bfbb509a0f1868d61e5a9b17fc19e87b35130be63f5dd6d6262233592adfb13b08c0b5d2a8ae4962d9a
|
|
7
|
+
data.tar.gz: 87559d0e479182188ec8643d788091921f7c019928c1085dfd95f1243b40771525c23f346e9140d8f9e259d95d2234382eec4ace9cba9b4dde96bcd41b912f57
|
|
@@ -5,13 +5,12 @@ module ForestAdminRpcAgent
|
|
|
5
5
|
class Agent < ForestAdminAgent::Builder::AgentFactory
|
|
6
6
|
include ForestAdminAgent::Http::Exceptions
|
|
7
7
|
|
|
8
|
-
attr_reader :rpc_collections, :cached_schema
|
|
8
|
+
attr_reader :rpc_collections, :cached_schema
|
|
9
9
|
|
|
10
10
|
def setup(options)
|
|
11
11
|
super
|
|
12
12
|
@rpc_collections = []
|
|
13
13
|
@cached_schema = nil
|
|
14
|
-
@cached_schema_hash = nil
|
|
15
14
|
@customizer = ForestAdminRpcAgent::DatasourceCustomizer.new
|
|
16
15
|
end
|
|
17
16
|
|
|
@@ -31,9 +30,7 @@ module ForestAdminRpcAgent
|
|
|
31
30
|
|
|
32
31
|
datasource = @container.resolve(:datasource)
|
|
33
32
|
|
|
34
|
-
# Build and cache RPC schema from live datasource
|
|
35
33
|
@cached_schema = build_rpc_schema_from_datasource(datasource)
|
|
36
|
-
compute_and_cache_hash
|
|
37
34
|
|
|
38
35
|
# Write schema file for reference (only in development mode)
|
|
39
36
|
# Uses the same serialization as the /rpc-schema route
|
|
@@ -54,11 +51,15 @@ module ForestAdminRpcAgent
|
|
|
54
51
|
self
|
|
55
52
|
end
|
|
56
53
|
|
|
57
|
-
# Check if provided hash matches the cached schema
|
|
54
|
+
# Check if provided hash matches the cached schema etag
|
|
58
55
|
def schema_hash_matches?(provided_hash)
|
|
59
|
-
return false unless @
|
|
56
|
+
return false unless @cached_schema && @cached_schema[:etag] && provided_hash
|
|
60
57
|
|
|
61
|
-
@
|
|
58
|
+
@cached_schema[:etag] == provided_hash
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def cached_schema_hash
|
|
62
|
+
@cached_schema&.dig(:etag)
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
private
|
|
@@ -131,6 +132,13 @@ module ForestAdminRpcAgent
|
|
|
131
132
|
schema[:native_query_connections] = datasource.live_query_connections.keys
|
|
132
133
|
.map { |connection_name| { name: connection_name } }
|
|
133
134
|
|
|
135
|
+
schema[:etag] = Digest::SHA1.hexdigest(schema.to_json)
|
|
136
|
+
|
|
137
|
+
ForestAdminRpcAgent::Facades::Container.logger.log(
|
|
138
|
+
'Debug',
|
|
139
|
+
"RPC agent schema etag computed: #{schema[:etag]}"
|
|
140
|
+
)
|
|
141
|
+
|
|
134
142
|
schema
|
|
135
143
|
end
|
|
136
144
|
|
|
@@ -141,16 +149,5 @@ module ForestAdminRpcAgent
|
|
|
141
149
|
@rpc_collections.include?(relation.foreign_collection)
|
|
142
150
|
end
|
|
143
151
|
end
|
|
144
|
-
|
|
145
|
-
def compute_and_cache_hash
|
|
146
|
-
return unless @cached_schema
|
|
147
|
-
|
|
148
|
-
@cached_schema_hash = Digest::SHA1.hexdigest(@cached_schema.to_json)
|
|
149
|
-
|
|
150
|
-
ForestAdminRpcAgent::Facades::Container.logger.log(
|
|
151
|
-
'Debug',
|
|
152
|
-
"RPC agent schema hash computed: #{@cached_schema_hash}"
|
|
153
|
-
)
|
|
154
|
-
end
|
|
155
152
|
end
|
|
156
153
|
end
|
|
@@ -15,22 +15,19 @@ module ForestAdminRpcAgent
|
|
|
15
15
|
def handle_request(args)
|
|
16
16
|
agent = ForestAdminRpcAgent::Agent.instance
|
|
17
17
|
client_etag = extract_if_none_match(args)
|
|
18
|
+
etag = agent.cached_schema_hash
|
|
18
19
|
|
|
19
|
-
# If client has cached schema and ETag matches, return 304 Not Modified
|
|
20
20
|
if client_etag && agent.schema_hash_matches?(client_etag)
|
|
21
21
|
ForestAdminRpcAgent::Facades::Container.logger.log(
|
|
22
22
|
'Debug',
|
|
23
23
|
'ETag matches, returning 304 Not Modified'
|
|
24
24
|
)
|
|
25
25
|
return { status: HTTP_NOT_MODIFIED, content: nil,
|
|
26
|
-
headers: { 'ETag' =>
|
|
26
|
+
headers: { 'ETag' => etag } }
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
# Get schema from cache (or build from datasource if not cached)
|
|
30
29
|
schema = agent.cached_schema
|
|
31
|
-
etag = agent.cached_schema_hash
|
|
32
30
|
|
|
33
|
-
# Return schema with ETag header
|
|
34
31
|
{
|
|
35
32
|
status: HTTP_OK,
|
|
36
33
|
content: schema,
|