Pool: remove redundant properties

This commit is contained in:
syeopite 2024-11-14 19:47:58 -08:00
parent aab9719e25
commit 6b3f665dfb
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 15 additions and 26 deletions

View File

@ -145,7 +145,7 @@ class Config
property idle_pool_size : Int32? = nil property idle_pool_size : Int32? = nil
# Amount of seconds to wait for a client to be free from the pool before rasing an error # 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 # HTTP Proxy configuration
property http_proxy : HTTPProxyConfig? = nil property http_proxy : HTTPProxyConfig? = nil

View File

@ -1,27 +1,31 @@
module Invidious::ConnectionPool module Invidious::ConnectionPool
struct Pool struct Pool
property! url : URI property url : URI
property! max_capacity : Int32
property! idle_capacity : Int32
property! timeout : Float64
property pool : DB::Pool(HTTP::Client) property pool : DB::Pool(HTTP::Client)
def initialize( def initialize(
url : URI, url : URI,
*, *,
@max_capacity : Int32 = 5, max_capacity : Int32 = 5,
idle_capacity : Int32? = nil, idle_capacity : Int32? = nil,
@timeout : Float64 = 5.0 timeout : Float64 = 5.0
) )
if idle_capacity.nil? if idle_capacity.nil?
@idle_capacity = @max_capacity idle_capacity = max_capacity
else
@idle_capacity = idle_capacity
end end
@url = url @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 end
{% for method in %w[get post put patch delete head options] %} {% for method in %w[get post put patch delete head options] %}
@ -76,21 +80,6 @@ module Invidious::ConnectionPool
ensure ensure
pool.release(http_client) if http_client && client_exists_in_pool pool.release(http_client) if http_client && client_exists_in_pool
end 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 end
class Error < Exception class Error < Exception