Skip to content

Commit

Permalink
Avoid unnecessary hash values
Browse files Browse the repository at this point in the history
This about halves the memory usage of the gem
  • Loading branch information
jhawthorn committed Dec 12, 2023
1 parent 1ea75fb commit 4329b8a
Show file tree
Hide file tree
Showing 6 changed files with 4,135 additions and 4,142 deletions.
4 changes: 1 addition & 3 deletions lib/elastomer_client/client/rest_api_spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class ApiSpec
attr_reader :common_params

def initialize
@rest_apis ||= {}
@common_params ||= {}
@common_params_set = Set.new(@common_params.keys)
@common_params_set = Set.new(@common_params)
end

# Given an API descriptor name and a set of request parameters, select those
Expand Down
2,706 changes: 1,352 additions & 1,354 deletions lib/elastomer_client/client/rest_api_spec/api_spec_v5_6.rb

Large diffs are not rendered by default.

5,522 changes: 2,761 additions & 2,761 deletions lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/elastomer_client/client/rest_api_spec/rest_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class Url
attr_reader :parts_keys
attr_reader :params_keys

def initialize(path:, paths: [], parts: {}, params: {})
def initialize(path:, paths: [], parts: [], params: [])
@path = path
@paths = Array(paths)
@parts_keys = parts.keys
@params_keys = params.keys
@parts_keys = parts
@params_keys = params

@parts_set = Set.new(@parts_keys)
@params_set = Set.new(@params_keys)
Expand Down
18 changes: 9 additions & 9 deletions script/generate-rest-api-spec
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,29 @@ module ElastomerClient::Client::RestApiSpec
path: "<%= generate_path(url) %>",
paths: <%= generate_paths(url) %>,
<% if (parts = generate_parts(url)) && !parts.empty? -%>
parts: {
parts: [
<% parts.each do |k,v| -%>
"<%= k %>" => <%= v.to_s %>,
"<%= k %>",
<% end -%>
},
],
<% end -%>
<% params = generate_params(data) -%>
<% if !params.nil? && !params.empty? -%>
params: {
params: [
<% params.each do |k,v| -%>
"<%= k %>" => <%= v.to_s %>,
"<%= k %>",
<% end -%>
}
]
<% end -%>
}
),
<% end -%>
}
@common_params = {
@common_params = [
<% each_common do |k,v| -%>
"<%= k %>" => <%= v.to_s %>,
"<%= k %>",
<% end -%>
}
]
super
end
end
Expand Down
21 changes: 9 additions & 12 deletions test/client/rest_api_spec/rest_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@
url: {
path: "/_cluster/state",
paths: ["/_cluster/state", "/_cluster/state/{metric}", "/_cluster/state/{metric}/{index}"],
parts: {
"index" => {"type"=>"list", "description"=>"A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices"},
"metric" => {"type"=>"list", "options"=>["_all", "blocks", "metadata", "nodes", "routing_table", "routing_nodes", "master_node", "version"], "description"=>"Limit the information returned to the specified metrics"},
},
params: {
"local" => {"type"=>"boolean", "description"=>"Return local information, do not retrieve the state from master node (default: false)"},
"master_timeout" => {"type"=>"time", "description"=>"Specify timeout for connection to master"},
"flat_settings" => {"type"=>"boolean", "description"=>"Return settings in flat format (default: false)"},
"ignore_unavailable" => {"type"=>"boolean", "description"=>"Whether specified concrete indices should be ignored when unavailable (missing or closed)"},
"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)"},
"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."},
}
parts: ["index", "metric"],
params: [
"local",
"master_timeout",
"flat_settings",
"ignore_unavailable",
"allow_no_indices",
"expand_wildcards"
]
}
end

Expand Down

0 comments on commit 4329b8a

Please sign in to comment.