Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hiera-mysql-json-backend-puppetserver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |gem|
gem.name = "hiera-mysql-json-backend-jruby"
gem.version = "2.2.0"
gem.version = "2.2.1"
gem.authors = ["Hostnet"]
gem.email = ["[email protected]"]
gem.description = %q{Alternative MySQL backend with json support for hiera}
Expand Down
2 changes: 1 addition & 1 deletion hiera-mysql-json-backend.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |gem|
gem.name = "hiera-mysql-json-backend"
gem.version = "2.2.0"
gem.version = "2.2.1"
gem.authors = ["Hostnet"]
gem.email = ["[email protected]"]
gem.description = %q{Alternative MySQL backend with json support for hiera}
Expand Down
11 changes: 10 additions & 1 deletion lib/hiera/backend/mysql_json_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(cache=nil)
end

@cache = cache || Filecache.new
@query_cache = {}

Hiera.debug('Hiera mysql_json initialized')
end
Expand Down Expand Up @@ -87,7 +88,15 @@ def lookup(key, scope, order_override, resolution_type)

query = Backend.parse_answer(data[key], scope)

sql_results = query(connection_hash, query)
@query_cache[source] = {} unless @query_cache.key?(source)
if @query_cache[source].key?(key)
Hiera.debug("Using cached query result for source #{source} and key #{key}.")
sql_results = @query_cache[source][key]
else
Hiera.debug("Executing query for source #{source} and key #{key}.")
sql_results = query(connection_hash, query)
@query_cache[source][key] = sql_results
end
# TODO: make sure we fail if we have more than 1 result, skip if less than 1.
next if sql_results.length != 1

Expand Down