Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): Fixes large and small image cache (#7726)

martyfuhry21caa06fa221
diff --git a/mobile/lib/shared/cache/custom_image_cache.dart b/mobile/lib/shared/cache/custom_image_cache.dart
index 79338cbda5..3f8b35e3fa 100644
--- a/mobile/lib/shared/cache/custom_image_cache.dart
+++ b/mobile/lib/shared/cache/custom_image_cache.dart
@@ -1,5 +1,6 @@
import 'package:flutter/painting.dart';
import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_local_image_provider.dart';
+import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_remote_image_provider.dart';
/// [ImageCache] that uses two caches for small and large images
/// so that a single large image does not evict all small iamges
@@ -31,9 +32,18 @@ final class CustomImageCache implements ImageCache {
_large.clearLiveImages();
}
+ /// Gets the cache for the given key
+ ImageCache _cacheForKey(Object key) =>
+ (key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
+ ? _large
+ : _small;
+
@override
- bool containsKey(Object key) =>
- (key is ImmichLocalImageProvider ? _large : _small).containsKey(key);
+ bool containsKey(Object key) {
+ // [ImmichLocalImageProvider] and [ImmichRemoteImageProvider] are both
+ // large size images while the other thumbnail providers are small
+ return _cacheForKey(key).containsKey(key);
+ }
@override
int get currentSize => _small.currentSize + _large.currentSize;
@@ -43,8 +53,7 @@ final class CustomImageCache implements ImageCache {
@override
bool evict(Object key, {bool includeLive = true}) =>
- (key is ImmichLocalImageProvider ? _large : _small)
- .evict(key, includeLive: includeLive);
+ _cacheForKey(key).evict(key, includeLive: includeLive);
@override
int get liveImageCount => _small.liveImageCount + _large.liveImageCount;
@@ -59,10 +68,9 @@ final class CustomImageCache implements ImageCache {
ImageStreamCompleter Function() loader, {
ImageErrorListener? onError,
}) =>
- (key is ImmichLocalImageProvider ? _large : _small)
- .putIfAbsent(key, loader, onError: onError);
+ _cacheForKey(key).putIfAbsent(key, loader, onError: onError);
@override
ImageCacheStatus statusForKey(Object key) =>
- (key is ImmichLocalImageProvider ? _large : _small).statusForKey(key);
+ _cacheForKey(key).statusForKey(key);
}