mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
avoid caching statements in pool_statement
Only the connections where it was prepared need to be cached. The connections already have a statement cache based on the query
This commit is contained in:
parent
f568e4506d
commit
9c9176608d
1 changed files with 7 additions and 11 deletions
|
@ -6,7 +6,8 @@ module DB
|
||||||
class PoolStatement
|
class PoolStatement
|
||||||
include StatementMethods
|
include StatementMethods
|
||||||
|
|
||||||
@statements = {} of Connection => Statement
|
# connections where the statement was prepared
|
||||||
|
@connections = Set(Connection).new
|
||||||
|
|
||||||
def initialize(@db : Database, @query : String)
|
def initialize(@db : Database, @query : String)
|
||||||
# Prepares a statement on some connection
|
# Prepares a statement on some connection
|
||||||
|
@ -24,7 +25,7 @@ module DB
|
||||||
|
|
||||||
# WHAT-IF the connection is busy? Should each statement be able to
|
# WHAT-IF the connection is busy? Should each statement be able to
|
||||||
# deallocate itself when the connection is free.
|
# deallocate itself when the connection is free.
|
||||||
@statements.clear
|
@connections.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
# See `QueryMethods#exec`
|
# See `QueryMethods#exec`
|
||||||
|
@ -58,16 +59,11 @@ module DB
|
||||||
end
|
end
|
||||||
|
|
||||||
# builds a statement over a real connection
|
# builds a statement over a real connection
|
||||||
# the conneciton and the stament is registered in `@statements`
|
# the conneciton is registered in `@connections`
|
||||||
private def get_statement : Statement
|
private def get_statement : Statement
|
||||||
conn, existing = @db.checkout_some(@statements.keys)
|
conn, existing = @db.checkout_some(@connections)
|
||||||
if existing
|
@connections << conn unless existing
|
||||||
@statements[conn]
|
conn.prepare(@query)
|
||||||
else
|
|
||||||
stmt = conn.prepare @query
|
|
||||||
@statements[conn] = stmt
|
|
||||||
stmt
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue