perf: type-aware image memory cache bounds

This commit is contained in:
edde746
2026-03-28 18:31:16 +01:00
parent 56697303f9
commit 684196aa36
3 changed files with 17 additions and 2 deletions
@@ -1299,6 +1299,7 @@ class _LibraryBrowseTabState extends BaseLibraryTabState<PlexMetadata, LibraryBr
final (_, memHeight) = PlexImageHelper.getMemCacheDimensions(
displayWidth: scaledWidth.isFinite && scaledWidth > 0 ? scaledWidth.round() : 0,
displayHeight: scaledHeight.isFinite && scaledHeight > 0 ? scaledHeight.round() : 0,
imageType: ImageType.poster,
);
precacheImage(
+15 -2
View File
@@ -198,16 +198,29 @@ class PlexImageHelper {
}
}
/// Generates cache-friendly dimensions for memory caching
/// Generates cache-friendly dimensions for memory caching.
///
/// Max bounds are type-aware so large originals (e.g. failed server
/// transcodes or external EPG images) are capped at a resolution
/// appropriate for the display context.
static (int memWidth, int memHeight) getMemCacheDimensions({
required int displayWidth,
required int displayHeight,
double scaleFactor = 1.0,
ImageType imageType = ImageType.poster,
}) {
final scaledWidth = (displayWidth * scaleFactor).round();
final scaledHeight = (displayHeight * scaleFactor).round();
return (scaledWidth.clamp(120, 1200), scaledHeight.clamp(180, 1800));
final (int maxW, int maxH) = switch (imageType) {
ImageType.poster => (720, 1080),
ImageType.thumb => (960, 540),
ImageType.art => (1920, 1080),
ImageType.logo => (600, 300),
ImageType.avatar => (300, 300),
};
return (scaledWidth.clamp(120, maxW), scaledHeight.clamp(180, maxH));
}
/// Determines if an image path is suitable for transcoding
+1
View File
@@ -329,6 +329,7 @@ class PlexOptimizedImage extends StatelessWidget {
final (memWidth, memHeight) = PlexImageHelper.getMemCacheDimensions(
displayWidth: scaledWidth.isFinite && scaledWidth > 0 ? scaledWidth.round() : 0,
displayHeight: scaledHeight.isFinite && scaledHeight > 0 ? scaledHeight.round() : 0,
imageType: imageType,
);
// Generate cache key if not provided