main_window: skip parallel httpx download for streamed videos

behavior change: when streaming=True (uncached video handed directly to
mpv), _load now early-returns instead of running download_image in
parallel. mpv's stream-record option (added in the previous commit)
handles cache population, so the parallel httpx download was a second
TCP+TLS connection to the same CDN URL contending with mpv for
bandwidth. Single connection per uncached video after this commit.
This commit is contained in:
pax 2026-04-09 20:53:23 -05:00
parent a01ac34944
commit d9830d0f68

View File

@ -1248,23 +1248,17 @@ class BooruApp(QMainWindow):
async def _load(): async def _load():
self._prefetch_pause.clear() # pause prefetch self._prefetch_pause.clear() # pause prefetch
try: try:
if streaming:
# mpv is streaming the URL directly and its
# stream-record option populates the cache as it
# plays. No parallel httpx download needed — that
# would open a second TCP+TLS connection to the
# same CDN URL, contending with mpv for bandwidth.
return
path = await download_image(post.file_url, progress_callback=_progress) path = await download_image(post.file_url, progress_callback=_progress)
if not streaming:
# Normal path: download finished, hand the local
# file to the preview/popout. For streaming, mpv
# is already playing the URL — calling set_media
# again with the local path would interrupt
# playback and reset position to 0, so we
# suppress image_done in that case and just let
# the cache write complete silently.
self._signals.image_done.emit(str(path), info) self._signals.image_done.emit(str(path), info)
except Exception as e: except Exception as e:
log.error(f"Image download failed: {e}") log.error(f"Image download failed: {e}")
if not streaming:
# If we're streaming, mpv has the URL — don't
# surface a "download failed" error since the
# user is likely watching the video right now.
# The cache just won't get populated for next time.
self._signals.image_error.emit(str(e)) self._signals.image_error.emit(str(e))
finally: finally:
self._prefetch_pause.set() # resume prefetch self._prefetch_pause.set() # resume prefetch