mirror of
https://github.com/yattee/yattee.git
synced 2026-05-13 10:55:03 +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:
@@ -145,12 +145,17 @@ final class InstancesManager {
|
||||
}
|
||||
|
||||
saveInstances()
|
||||
Task { await ProxyDetectionCache.shared.invalidate(instance: instance) }
|
||||
}
|
||||
|
||||
func update(_ instance: Instance) {
|
||||
if let index = instances.firstIndex(where: { $0.id == instance.id }) {
|
||||
instances[index] = instance
|
||||
saveInstances()
|
||||
// Editing a source can change the proxy answer (URL change, toggle
|
||||
// flip). Drop the cached auto-detect verdict so the next playback
|
||||
// re-probes.
|
||||
Task { await ProxyDetectionCache.shared.invalidate(instance: instance) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user