fix(plex): retry slow library hubs
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/media_server_http_client.dart';
|
||||
|
||||
final _artworkHttpClient = MediaServerHttpClient(usePlexApiClient: true);
|
||||
|
||||
/// Shared cache manager for media-server image artwork. Used for both Plex and
|
||||
/// Jellyfin artwork (the class name predates Jellyfin support — it's
|
||||
/// backend-neutral).
|
||||
@@ -13,7 +15,8 @@ import '../utils/media_server_http_client.dart';
|
||||
/// Uses the platform-native HTTP client so iOS/macOS (CupertinoClient) and
|
||||
/// Android (CronetClient) benefit from HTTP/2 connection multiplexing —
|
||||
/// many concurrent image downloads over a single connection instead of
|
||||
/// being limited to a handful of HTTP/1.1 connections.
|
||||
/// being limited to a handful of HTTP/1.1 connections. On Linux this uses the
|
||||
/// same finite-connection tuning as Plex API traffic.
|
||||
class PlexImageCacheManager extends ce_cache.DefaultCacheManager {
|
||||
static final PlexImageCacheManager instance = PlexImageCacheManager._();
|
||||
|
||||
@@ -21,7 +24,7 @@ class PlexImageCacheManager extends ce_cache.DefaultCacheManager {
|
||||
: super(
|
||||
stalePeriod: const Duration(days: 14),
|
||||
maxNrOfCacheObjects: 3000,
|
||||
httpClientFactory: () => _SharedHttpClient(httpClient.inner),
|
||||
httpClientFactory: () => _SharedHttpClient(_artworkHttpClient.inner),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1542,10 +1542,16 @@ class PlexClient with MediaServerCacheMixin, _PlexLiveTvClientMethods implements
|
||||
/// Returns a list of recommendation hubs like "Trending Movies", "Top in Genre", etc.
|
||||
Future<List<PlexHubDto>> _getLibraryHubs(String sectionId, {int limit = 10}) async {
|
||||
try {
|
||||
final response = await _getWithFailover(
|
||||
'/hubs/sections/$sectionId',
|
||||
queryParameters: {'count': limit, 'includeGuids': 1},
|
||||
allowEndpointFailover: false,
|
||||
final response = await retryTransientMediaServerCall(
|
||||
operation: 'Plex library hubs',
|
||||
attemptTimeouts: MediaServerTimeouts.libraryHubAttemptTimeouts,
|
||||
call: (timeout, abort) => _getWithFailover(
|
||||
'/hubs/sections/$sectionId',
|
||||
queryParameters: {'count': limit, 'includeGuids': 1},
|
||||
timeout: timeout,
|
||||
abort: abort,
|
||||
allowEndpointFailover: false,
|
||||
),
|
||||
);
|
||||
final sid = serverId;
|
||||
final sname = serverName;
|
||||
|
||||
@@ -11,6 +11,10 @@ class MediaServerTimeouts {
|
||||
/// while Plex wakes idle disks, but should not block forever.
|
||||
static const homeHubAttemptTimeouts = [Duration(seconds: 10), Duration(seconds: 5), Duration(milliseconds: 2500)];
|
||||
|
||||
/// Retry budget for per-library home hub rows (`/hubs/sections/{id}`). These
|
||||
/// can be slower than the top-level home hub call on remote Plex servers.
|
||||
static const libraryHubAttemptTimeouts = [Duration(seconds: 10), Duration(seconds: 8), Duration(seconds: 5)];
|
||||
|
||||
/// Timeout for probing a cached/preferred endpoint before falling back to
|
||||
/// the full candidate race (used in [PlexServer.findBestWorkingConnection]).
|
||||
static const preferredEndpointProbe = Duration(milliseconds: 1500);
|
||||
|
||||
Reference in New Issue
Block a user