Connection pooling for thumbnails, wider score spinbox

Shared httpx.AsyncClient reuses TLS connections across thumbnail
downloads — avoids 40 separate TLS handshakes per page on Windows.
Score spinbox widened to 90px with explicit arrow buttons.
This commit is contained in:
pax 2026-04-05 16:19:10 -05:00
parent 9d11a403d7
commit ee9d06755f
2 changed files with 23 additions and 12 deletions

View File

@ -35,6 +35,25 @@ def _url_hash(url: str) -> str:
return hashlib.sha256(url.encode()).hexdigest()[:16] return hashlib.sha256(url.encode()).hexdigest()[:16]
# Shared httpx client for connection pooling (avoids per-request TLS handshakes)
_shared_client: httpx.AsyncClient | None = None
def _get_shared_client(referer: str = "") -> httpx.AsyncClient:
global _shared_client
if _shared_client is None or _shared_client.is_closed:
_shared_client = httpx.AsyncClient(
headers={
"User-Agent": USER_AGENT,
"Accept": "image/*,video/*,*/*",
},
follow_redirects=True,
timeout=60.0,
limits=httpx.Limits(max_connections=10, max_keepalive_connections=5),
)
return _shared_client
_IMAGE_MAGIC = { _IMAGE_MAGIC = {
b'\x89PNG': True, b'\x89PNG': True,
b'\xff\xd8\xff': True, # JPEG b'\xff\xd8\xff': True, # JPEG
@ -142,15 +161,7 @@ async def download_image(
own_client = client is None own_client = client is None
if own_client: if own_client:
client = httpx.AsyncClient( client = _get_shared_client()
headers={
"User-Agent": USER_AGENT,
"Referer": referer,
"Accept": "image/*,video/*,*/*",
},
follow_redirects=True,
timeout=60.0,
)
try: try:
if progress_callback: if progress_callback:
async with client.stream("GET", url) as resp: async with client.stream("GET", url) as resp:
@ -184,8 +195,7 @@ async def download_image(
if local.suffix.lower() == ".zip" and zipfile.is_zipfile(local): if local.suffix.lower() == ".zip" and zipfile.is_zipfile(local):
local = _convert_ugoira_to_gif(local) local = _convert_ugoira_to_gif(local)
finally: finally:
if own_client: pass # shared client stays open for connection reuse
await client.aclose()
return local return local

View File

@ -304,7 +304,8 @@ class BooruApp(QMainWindow):
self._score_spin = QSpinBox() self._score_spin = QSpinBox()
self._score_spin.setRange(0, 99999) self._score_spin.setRange(0, 99999)
self._score_spin.setValue(0) self._score_spin.setValue(0)
self._score_spin.setFixedWidth(70) self._score_spin.setFixedWidth(90)
self._score_spin.setButtonSymbols(QSpinBox.ButtonSymbols.UpDownArrows)
top.addWidget(self._score_spin) top.addWidget(self._score_spin)
self._search_bar = SearchBar(db=self._db) self._search_bar = SearchBar(db=self._db)