Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@ version: 2.0
shards:
db:
git: https://github.com/crystal-lang/crystal-db.git
version: 0.10.0
version: 0.10.1

exception_page:
git: https://github.com/crystal-loot/exception_page.git
version: 0.1.4
version: 0.1.5

kemal:
git: https://github.com/kemalcr/kemal.git
version: 0.27.0
version: 1.0.0

kilt:
git: https://github.com/jeromegn/kilt.git
version: 0.4.0
version: 0.4.1

lsquic:
git: https://github.com/iv-org/lsquic.cr.git
version: 2.18.1-1
version: 2.18.1-2

pg:
git: https://github.com/will/crystal-pg.git
version: 0.23.1

pool:
git: https://github.com/ysbaddaden/pool.git
version: 0.2.3
version: 0.23.2

protodec:
git: https://github.com/omarroth/protodec.git
version: 0.1.3
version: 0.1.4

radix:
git: https://github.com/luislavena/radix.git
version: 0.3.9
version: 0.4.1

sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
Expand Down
11 changes: 4 additions & 7 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ targets:
dependencies:
pg:
github: will/crystal-pg
version: ~> 0.23.1
version: ~> 0.23.2
sqlite3:
github: crystal-lang/crystal-sqlite3
version: ~> 0.18.0
kemal:
github: kemalcr/kemal
version: ~> 0.27.0
pool:
github: ysbaddaden/pool
version: ~> 0.2.3
version: ~> 1.0.0
protodec:
github: omarroth/protodec
version: ~> 0.1.3
version: ~> 0.1.4
lsquic:
github: iv-org/lsquic.cr
version: ~> 2.18.1-1

crystal: 0.36.1
crystal: 1.0.0

license: AGPLv3
8 changes: 4 additions & 4 deletions src/invidious/helpers/utils.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "lsquic"
require "pool/connection"
require "db"

def add_yt_headers(request)
request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
Expand All @@ -20,7 +20,7 @@ struct QUICPool
property! url : URI
property! capacity : Int32
property! timeout : Float64
property pool : ConnectionPool(QUIC::Client)
property pool : DB::Pool(QUIC::Client)

def initialize(url : URI, @capacity = 5, @timeout = 5.0)
@url = url
Expand All @@ -43,15 +43,15 @@ struct QUICPool
conn.before_request { |r| add_yt_headers(r) } if url.host == "www.youtube.com"
response = yield conn
ensure
pool.checkin(conn)
pool.release(conn)
end
end

response
end

private def build_pool
ConnectionPool(QUIC::Client).new(capacity: capacity, timeout: timeout) do
DB::Pool(QUIC::Client).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do
conn = QUIC::Client.new(url)
conn.family = (url.host == "www.youtube.com") ? CONFIG.force_resolve : Socket::Family::INET
conn.family = Socket::Family::INET if conn.family == Socket::Family::UNSPEC
Expand Down