mirror of
https://github.com/yattee/yattee.git
synced 2026-05-12 10:25:02 +00:00
Cache and prewarm Invidious proxy auto-detection
The proxy auto-detect path (when proxiesVideos is off) HEADed a googlevideo URL with a 5 s timeout on every video. The verdict is a property of the network, not the video, so the cost was paid for no reason on videos 2..N. On a network where the CDN is blocked the full 5 s timeout was added to playback startup every single time. Two changes: 1) ProxyDetectionCache (actor, per-instance, 10 min TTL). First miss pays the HEAD once and caches the verdict; subsequent videos hit the cache synchronously. Concurrent callers share one in-flight probe. The last-seen sample CDN URL is retained so future probes don't need a fresh URL from the current video. 2) PlayerService kicks off InvidiousAPI.prewarmProxyDetection() in parallel with the videoWith... API call. By the time streams come back, the verdict is usually already cached and proxyStreamsIfNeeded is a sync lookup. Cheap when there's nothing to prewarm. Cache invalidation: - on InstancesManager.update (URL change, proxy toggle flip) - on InstancesManager.remove - TTL covers the network-change case for now (no NWPathMonitor yet)
This commit is contained in:
@@ -1659,6 +1659,12 @@ final class PlayerService {
|
||||
return (result.video, result.streams, result.captions, [])
|
||||
}
|
||||
|
||||
// Race the proxy-detection HEAD against the video API call so the
|
||||
// verdict is (usually) ready by the time streams come back. Cheap
|
||||
// when there's nothing to do — it returns immediately if the
|
||||
// verdict is already cached, or if no prior CDN sample exists.
|
||||
async let _: Void = InvidiousAPI.prewarmProxyDetection(for: instance)
|
||||
|
||||
// Fetch full video details, streams, captions, and storyboards in a single API call
|
||||
// (for Invidious, this is a single request; for other backends, calls are made in parallel)
|
||||
let result = try await contentService.videoWithStreamsAndCaptionsAndStoryboards(id: video.id.videoID, instance: instance)
|
||||
|
||||
Reference in New Issue
Block a user