mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-22 05:27:21 +00:00
Pool: remove redundant properties
This commit is contained in:
parent
aab9719e25
commit
6b3f665dfb
@ -145,7 +145,7 @@ class Config
|
||||
property idle_pool_size : Int32? = nil
|
||||
|
||||
# Amount of seconds to wait for a client to be free from the pool before rasing an error
|
||||
property pool_checkout_timeout : Int32 = 5
|
||||
property pool_checkout_timeout : Float64 = 5
|
||||
|
||||
# HTTP Proxy configuration
|
||||
property http_proxy : HTTPProxyConfig? = nil
|
||||
|
@ -1,27 +1,31 @@
|
||||
module Invidious::ConnectionPool
|
||||
struct Pool
|
||||
property! url : URI
|
||||
property! max_capacity : Int32
|
||||
property! idle_capacity : Int32
|
||||
property! timeout : Float64
|
||||
property url : URI
|
||||
property pool : DB::Pool(HTTP::Client)
|
||||
|
||||
def initialize(
|
||||
url : URI,
|
||||
*,
|
||||
@max_capacity : Int32 = 5,
|
||||
max_capacity : Int32 = 5,
|
||||
idle_capacity : Int32? = nil,
|
||||
@timeout : Float64 = 5.0
|
||||
timeout : Float64 = 5.0
|
||||
)
|
||||
if idle_capacity.nil?
|
||||
@idle_capacity = @max_capacity
|
||||
else
|
||||
@idle_capacity = idle_capacity
|
||||
idle_capacity = max_capacity
|
||||
end
|
||||
|
||||
@url = url
|
||||
|
||||
@pool = build_pool()
|
||||
options = DB::Pool::Options.new(
|
||||
initial_pool_size: 0,
|
||||
max_pool_size: max_capacity,
|
||||
max_idle_pool_size: idle_capacity,
|
||||
checkout_timeout: timeout
|
||||
)
|
||||
|
||||
@pool = DB::Pool(HTTP::Client).new(options) do
|
||||
next make_client(url, force_resolve: true)
|
||||
end
|
||||
end
|
||||
|
||||
{% for method in %w[get post put patch delete head options] %}
|
||||
@ -76,21 +80,6 @@ module Invidious::ConnectionPool
|
||||
ensure
|
||||
pool.release(http_client) if http_client && client_exists_in_pool
|
||||
end
|
||||
|
||||
private def build_pool
|
||||
# We call the getter for the instance variables instead of using them directly
|
||||
# because the getters defined by property! ensures that the value is not a nil
|
||||
options = DB::Pool::Options.new(
|
||||
initial_pool_size: 0,
|
||||
max_pool_size: max_capacity,
|
||||
max_idle_pool_size: idle_capacity,
|
||||
checkout_timeout: timeout
|
||||
)
|
||||
|
||||
DB::Pool(HTTP::Client).new(options) do
|
||||
next make_client(url, force_resolve: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Error < Exception
|
||||
|
Loading…
Reference in New Issue
Block a user