Skip to content

perf(streams): refresh stale cached sources asynchronously - #302

Open
veenix wants to merge 1 commit into
lostb1t:mainfrom
veenix:perf/cached-stream-refresh
Open

perf(streams): refresh stale cached sources asynchronously#302
veenix wants to merge 1 commit into
lostb1t:mainfrom
veenix:perf/cached-stream-refresh

Conversation

@veenix

@veenix veenix commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • return existing cached torrent sources without waiting for provider refreshes
  • refresh stale torrent-only source sets in a background task
  • keep cold loads synchronous when no usable cached source exists
  • refresh HTTP/debrid and mixed source sets synchronously so expiring URLs are not served stale
  • serialize refreshes per media item and re-check freshness after acquiring the lock

Why

After the stream cache TTL expires, item requests currently wait for every configured provider even when the server already has durable cached torrent descriptors. That adds provider latency to detail-page loading and playback controls. Serving those descriptors while revalidating removes the blocking delay without changing cold-item behavior.

The optimization is intentionally limited to torrent-only caches. HTTP and debrid URLs may expire, so those sources continue to refresh before they are returned.

Tests

  • focused torrent-only versus HTTP/debrid cache policy test
  • full remux-server suite passes on the integration stack: 581 passed
  • cargo fmt --all --check
  • cargo clippy -p remux-server --all-targets -- -D warnings

AI Disclosure

Created in collaboration with Codex

@veenix
veenix marked this pull request as ready for review August 21, 2026 20:09
@veenix
veenix marked this pull request as draft August 21, 2026 23:10
@veenix
veenix force-pushed the perf/cached-stream-refresh branch from ec72ce1 to f1b49aa Compare August 21, 2026 23:10
@veenix
veenix marked this pull request as ready for review August 22, 2026 04:43
let mut media = media.clone();
let ctx = ctx.clone();
tokio::spawn(async move {
let _guard = STREAM_LOCKS

@lostb1t lostb1t Aug 22, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we can keep this dry; the refresh logic seems to be the same for background and live. Probably worth moving it into the inner function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants