mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Honor prepared_statements_cache option in database also
This commit is contained in:
parent
7288baa3dd
commit
3aaccec206
2 changed files with 23 additions and 1 deletions
|
@ -239,6 +239,24 @@ describe DB::Database do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "prepared_statements_cache connection option" do
|
||||||
|
it "should reuse prepared statements if true" do
|
||||||
|
with_dummy "dummy://localhost:1027?prepared_statements=true&prepared_statements_cache=true" do |db|
|
||||||
|
stmt1 = db.build("the query")
|
||||||
|
stmt2 = db.build("the query")
|
||||||
|
stmt1.object_id.should eq(stmt2.object_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not reuse prepared statements if false" do
|
||||||
|
with_dummy "dummy://localhost:1027?prepared_statements=true&prepared_statements_cache=false" do |db|
|
||||||
|
stmt1 = db.build("the query")
|
||||||
|
stmt2 = db.build("the query")
|
||||||
|
stmt1.object_id.should_not eq(stmt2.object_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "unprepared statements in pool" do
|
describe "unprepared statements in pool" do
|
||||||
it "creating statements should not create new connections" do
|
it "creating statements should not create new connections" do
|
||||||
with_dummy "dummy://localhost:1027?initial_pool_size=1" do |db|
|
with_dummy "dummy://localhost:1027?initial_pool_size=1" do |db|
|
||||||
|
|
|
@ -95,7 +95,11 @@ module DB
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def fetch_or_build_prepared_statement(query) : PoolStatement
|
def fetch_or_build_prepared_statement(query) : PoolStatement
|
||||||
|
if @connection_options.prepared_statements_cache
|
||||||
@statements_cache.fetch(query) { build_prepared_statement(query) }
|
@statements_cache.fetch(query) { build_prepared_statement(query) }
|
||||||
|
else
|
||||||
|
build_prepared_statement(query)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue