Skip to content

Commit

Permalink
Merge pull request Kong#618 from Mashape/perf/dao
Browse files Browse the repository at this point in the history
perf(base_dao) Cache session_uniq_addr result
  • Loading branch information
thibaultcha committed Oct 13, 2015
2 parents 7338805 + fd94bc3 commit 495bcae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kong/dao/cassandra/base_dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ function BaseDao:get_or_prepare_stmt(session, query)
end

local statement, err
local session_addr = session_uniq_addr(session)
-- Retrieve the prepared statement from cache or prepare and cache
if self._statements_cache[session_uniq_addr(session)] and self._statements_cache[session_uniq_addr(session)][query] then
statement = self._statements_cache[session_uniq_addr(session)][query]
if self._statements_cache[session_addr] and self._statements_cache[session_addr][query] then
statement = self._statements_cache[session_addr][query]
else
statement, err = self:prepare_stmt(session, query)
if err then
Expand Down Expand Up @@ -333,13 +334,14 @@ function BaseDao:prepare_stmt(session, query)
if prepare_err then
return nil, DaoError("Failed to prepare statement: \""..query.."\". "..prepare_err, error_types.DATABASE)
else
local session_addr = session_uniq_addr(session)
-- cache of prepared statements must be specific to each node
if not self._statements_cache[session_uniq_addr(session)] then
self._statements_cache[session_uniq_addr(session)] = {}
if not self._statements_cache[session_addr] then
self._statements_cache[session_addr] = {}
end

-- cache key is the non-striped/non-formatted query from _queries
self._statements_cache[session_uniq_addr(session)][query] = prepared_stmt
self._statements_cache[session_addr][query] = prepared_stmt
return prepared_stmt
end
end
Expand Down

0 comments on commit 495bcae

Please sign in to comment.