Skip to content

Commit 664d22b

Browse files
committed
Avoid unnecessary hash values
This about halves the memory usage of the gem
1 parent 99760f9 commit 664d22b

File tree

8 files changed

+9651
-9658
lines changed

8 files changed

+9651
-9658
lines changed

lib/elastomer_client/client/rest_api_spec/api_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class ApiSpec
1212
attr_reader :common_params
1313

1414
def initialize
15-
@rest_apis ||= {}
16-
@common_params ||= {}
17-
@common_params_set = Set.new(@common_params.keys)
15+
@common_params_set = Set.new(@common_params)
1816
end
1917

2018
# Given an API descriptor name and a set of request parameters, select those

lib/elastomer_client/client/rest_api_spec/api_spec_v5_6.rb

Lines changed: 1352 additions & 1354 deletions
Large diffs are not rendered by default.

lib/elastomer_client/client/rest_api_spec/api_spec_v7_17.rb

Lines changed: 2765 additions & 2765 deletions
Large diffs are not rendered by default.

lib/elastomer_client/client/rest_api_spec/api_spec_v8_6.rb

Lines changed: 2751 additions & 2751 deletions
Large diffs are not rendered by default.

lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb

Lines changed: 2761 additions & 2761 deletions
Large diffs are not rendered by default.

lib/elastomer_client/client/rest_api_spec/rest_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class Url
3131
attr_reader :parts_keys
3232
attr_reader :params_keys
3333

34-
def initialize(path:, paths: [], parts: {}, params: {})
34+
def initialize(path:, paths: [], parts: [], params: [])
3535
@path = path
3636
@paths = Array(paths)
37-
@parts_keys = parts.keys
38-
@params_keys = params.keys
37+
@parts_keys = parts
38+
@params_keys = params
3939

4040
@parts_set = Set.new(@parts_keys)
4141
@params_set = Set.new(@params_keys)

script/generate-rest-api-spec

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,29 @@ module ElastomerClient::Client::RestApiSpec
178178
path: "<%= generate_path(url) %>",
179179
paths: <%= generate_paths(url) %>,
180180
<% if (parts = generate_parts(url)) && !parts.empty? -%>
181-
parts: {
181+
parts: [
182182
<% parts.each do |k,v| -%>
183-
"<%= k %>" => <%= v.to_s %>,
183+
"<%= k %>",
184184
<% end -%>
185-
},
185+
],
186186
<% end -%>
187187
<% params = generate_params(data) -%>
188188
<% if !params.nil? && !params.empty? -%>
189-
params: {
189+
params: [
190190
<% params.each do |k,v| -%>
191-
"<%= k %>" => <%= v.to_s %>,
191+
"<%= k %>",
192192
<% end -%>
193-
}
193+
]
194194
<% end -%>
195195
}
196196
),
197197
<% end -%>
198198
}
199-
@common_params = {
199+
@common_params = [
200200
<% each_common do |k,v| -%>
201-
"<%= k %>" => <%= v.to_s %>,
201+
"<%= k %>",
202202
<% end -%>
203-
}
203+
]
204204
super
205205
end
206206
end

test/client/rest_api_spec/rest_api_test.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@
1111
url: {
1212
path: "/_cluster/state",
1313
paths: ["/_cluster/state", "/_cluster/state/{metric}", "/_cluster/state/{metric}/{index}"],
14-
parts: {
15-
"index" => {"type"=>"list", "description"=>"A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices"},
16-
"metric" => {"type"=>"list", "options"=>["_all", "blocks", "metadata", "nodes", "routing_table", "routing_nodes", "master_node", "version"], "description"=>"Limit the information returned to the specified metrics"},
17-
},
18-
params: {
19-
"local" => {"type"=>"boolean", "description"=>"Return local information, do not retrieve the state from master node (default: false)"},
20-
"master_timeout" => {"type"=>"time", "description"=>"Specify timeout for connection to master"},
21-
"flat_settings" => {"type"=>"boolean", "description"=>"Return settings in flat format (default: false)"},
22-
"ignore_unavailable" => {"type"=>"boolean", "description"=>"Whether specified concrete indices should be ignored when unavailable (missing or closed)"},
23-
"allow_no_indices" => {"type"=>"boolean", "description"=>"Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"},
24-
"expand_wildcards" => {"type"=>"enum", "options"=>["open", "closed", "none", "all"], "default"=>"open", "description"=>"Whether to expand wildcard expression to concrete indices that are open, closed or both."},
25-
}
14+
parts: ["index", "metric"],
15+
params: [
16+
"local",
17+
"master_timeout",
18+
"flat_settings",
19+
"ignore_unavailable",
20+
"allow_no_indices",
21+
"expand_wildcards"
22+
]
2623
}
2724
end
2825

0 commit comments

Comments
 (0)