perf: limit concurrent image transcode requests
This commit is contained in:
+2
-1
@@ -79,7 +79,8 @@ void main() async {
|
||||
await initializeDateFormatting(savedLocale.languageCode, null);
|
||||
|
||||
// Configure image cache for large libraries
|
||||
PaintingBinding.instance.imageCache.maximumSizeBytes = 200 << 20; // 200MB
|
||||
PaintingBinding.instance.imageCache.maximumSize = 2000; // default 1000
|
||||
PaintingBinding.instance.imageCache.maximumSizeBytes = 300 << 20; // 300MB
|
||||
|
||||
// Initialize services in parallel where possible
|
||||
final futures = <Future<void>>[];
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:http/io_client.dart';
|
||||
|
||||
/// Custom cache manager for Plex image transcoding with connection limiting.
|
||||
///
|
||||
/// Limits concurrent HTTP connections to 6 per host (matching browser HTTP/1.1
|
||||
/// behavior) to prevent overwhelming the Plex server's transcode pipeline when
|
||||
/// many posters are visible simultaneously.
|
||||
class PlexImageCacheManager extends CacheManager with ImageCacheManager {
|
||||
static const _key = 'plexImageCache';
|
||||
|
||||
static final PlexImageCacheManager instance = PlexImageCacheManager._();
|
||||
|
||||
PlexImageCacheManager._()
|
||||
: super(
|
||||
Config(
|
||||
_key,
|
||||
stalePeriod: const Duration(days: 30),
|
||||
maxNrOfCacheObjects: 5000,
|
||||
fileService: HttpFileService(
|
||||
httpClient: IOClient(
|
||||
HttpClient()..maxConnectionsPerHost = 6,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:plezy/widgets/app_icon.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../services/image_cache_service.dart';
|
||||
import '../../services/plex_client.dart';
|
||||
import '../utils/plex_image_helper.dart';
|
||||
import 'media_card.dart';
|
||||
@@ -338,6 +339,7 @@ class PlexOptimizedImage extends StatelessWidget {
|
||||
image: CachedNetworkImageProvider(
|
||||
imageUrl,
|
||||
cacheKey: effectiveCacheKey,
|
||||
cacheManager: PlexImageCacheManager.instance,
|
||||
headers: const {'User-Agent': 'Plezy'},
|
||||
maxHeight: memHeight,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user