mirror of
https://github.com/immich-app/immich.git
synced 2024-11-15 09:59:00 -07:00
fix(mobile): Fixes memory image cache for local images (#9019)
* Fixes equality operator for immich local image provider * Changes image cache manager to no longer be image cache managers * Updates large image cache to 12 images format * Try 5 Image cache --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
2943f93098
commit
732bd1e652
@ -13,7 +13,7 @@ import 'package:immich_mobile/shared/models/store.dart';
|
||||
class ImageLoader {
|
||||
static Future<ui.Codec> loadImageFromCache(
|
||||
String uri, {
|
||||
required ImageCacheManager cache,
|
||||
required CacheManager cache,
|
||||
required ImageDecoderCallback decode,
|
||||
StreamController<ImageChunkEvent>? chunkEvents,
|
||||
}) async {
|
||||
@ -21,7 +21,7 @@ class ImageLoader {
|
||||
'x-immich-user-token': Store.get(StoreKey.accessToken),
|
||||
};
|
||||
|
||||
final stream = cache.getImageFile(
|
||||
final stream = cache.getFileStream(
|
||||
uri,
|
||||
withProgress: chunkEvents != null,
|
||||
headers: headers,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
/// The cache manager for full size images [ImmichRemoteImageProvider]
|
||||
class RemoteImageCacheManager extends CacheManager with ImageCacheManager {
|
||||
class RemoteImageCacheManager extends CacheManager {
|
||||
static const key = 'remoteImageCacheKey';
|
||||
static final RemoteImageCacheManager _instance = RemoteImageCacheManager._();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
/// The cache manager for thumbnail images [ImmichRemoteThumbnailProvider]
|
||||
class ThumbnailImageCacheManager extends CacheManager with ImageCacheManager {
|
||||
class ThumbnailImageCacheManager extends CacheManager {
|
||||
static const key = 'thumbnailImageCacheKey';
|
||||
static final ThumbnailImageCacheManager _instance =
|
||||
ThumbnailImageCacheManager._();
|
||||
|
@ -10,7 +10,6 @@ import 'package:immich_mobile/shared/models/asset.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
||||
/// The local image provider for an asset
|
||||
/// Only viable
|
||||
class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||
final Asset asset;
|
||||
|
||||
@ -94,9 +93,12 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (other is! ImmichLocalImageProvider) return false;
|
||||
if (identical(this, other)) return true;
|
||||
return asset == other.asset;
|
||||
if (other is ImmichLocalImageProvider) {
|
||||
return asset == other.asset;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -21,7 +21,7 @@ class ImmichRemoteImageProvider
|
||||
final String assetId;
|
||||
|
||||
/// The image cache manager
|
||||
final ImageCacheManager? cacheManager;
|
||||
final CacheManager? cacheManager;
|
||||
|
||||
ImmichRemoteImageProvider({
|
||||
required this.assetId,
|
||||
@ -66,7 +66,7 @@ class ImmichRemoteImageProvider
|
||||
// Streams in each stage of the image as we ask for it
|
||||
Stream<ui.Codec> _codec(
|
||||
ImmichRemoteImageProvider key,
|
||||
ImageCacheManager cache,
|
||||
CacheManager cache,
|
||||
ImageDecoderCallback decode,
|
||||
StreamController<ImageChunkEvent> chunkEvents,
|
||||
) async* {
|
||||
|
@ -22,7 +22,7 @@ class ImmichRemoteThumbnailProvider
|
||||
final int? width;
|
||||
|
||||
/// The image cache manager
|
||||
final ImageCacheManager? cacheManager;
|
||||
final CacheManager? cacheManager;
|
||||
|
||||
ImmichRemoteThumbnailProvider({
|
||||
required this.assetId,
|
||||
@ -55,7 +55,7 @@ class ImmichRemoteThumbnailProvider
|
||||
// Streams in each stage of the image as we ask for it
|
||||
Stream<ui.Codec> _codec(
|
||||
ImmichRemoteThumbnailProvider key,
|
||||
ImageCacheManager cache,
|
||||
CacheManager cache,
|
||||
ImageDecoderCallback decode,
|
||||
) async* {
|
||||
// Load a preview to the chunk events
|
||||
|
@ -1,12 +1,14 @@
|
||||
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_local_thumbnail_provider.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_remote_image_provider.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/image_providers/immich_remote_thumbnail_provider.dart';
|
||||
|
||||
/// [ImageCache] that uses two caches for small and large images
|
||||
/// so that a single large image does not evict all small iamges
|
||||
final class CustomImageCache implements ImageCache {
|
||||
final _small = ImageCache();
|
||||
final _large = ImageCache();
|
||||
final _large = ImageCache()..maximumSize = 5; // Maximum 5 images
|
||||
|
||||
@override
|
||||
int get maximumSize => _small.maximumSize + _large.maximumSize;
|
||||
@ -33,6 +35,8 @@ final class CustomImageCache implements ImageCache {
|
||||
}
|
||||
|
||||
/// Gets the cache for the given key
|
||||
/// [_large] is used for [ImmichLocalImageProvider] and [ImmichRemoteImageProvider]
|
||||
/// [_small] is used for [ImmichLocalThumbnailProvider] and [ImmichRemoteThumbnailProvider]
|
||||
ImageCache _cacheForKey(Object key) =>
|
||||
(key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
|
||||
? _large
|
||||
|
Loading…
Reference in New Issue
Block a user