1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-28 09:33:27 +02:00

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

Fixes large and small image cache
This commit is contained in:
martyfuhry 2024-03-07 21:55:50 -05:00 committed by GitHub
parent 7a7475ed67
commit 21caa06fa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}