Skip to content

Start caching mysql results #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -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}
2 changes: 1 addition & 1 deletion hiera-mysql-json-backend.gemspec
Original file line number Diff line number Diff line change
@@ -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}
11 changes: 10 additions & 1 deletion lib/hiera/backend/mysql_json_backend.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ def initialize(cache=nil)
end

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

Hiera.debug('Hiera mysql_json initialized')
end
@@ -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