mirror of
https://github.com/immich-app/immich.git
synced 2025-01-01 08:31:59 +00: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
7 changed files with 18 additions and 12 deletions
|
@ -13,7 +13,7 @@ import 'package:immich_mobile/shared/models/store.dart';
|
||||||
class ImageLoader {
|
class ImageLoader {
|
||||||
static Future<ui.Codec> loadImageFromCache(
|
static Future<ui.Codec> loadImageFromCache(
|
||||||
String uri, {
|
String uri, {
|
||||||
required ImageCacheManager cache,
|
required CacheManager cache,
|
||||||
required ImageDecoderCallback decode,
|
required ImageDecoderCallback decode,
|
||||||
StreamController<ImageChunkEvent>? chunkEvents,
|
StreamController<ImageChunkEvent>? chunkEvents,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -21,7 +21,7 @@ class ImageLoader {
|
||||||
'x-immich-user-token': Store.get(StoreKey.accessToken),
|
'x-immich-user-token': Store.get(StoreKey.accessToken),
|
||||||
};
|
};
|
||||||
|
|
||||||
final stream = cache.getImageFile(
|
final stream = cache.getFileStream(
|
||||||
uri,
|
uri,
|
||||||
withProgress: chunkEvents != null,
|
withProgress: chunkEvents != null,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||||
|
|
||||||
/// The cache manager for full size images [ImmichRemoteImageProvider]
|
/// The cache manager for full size images [ImmichRemoteImageProvider]
|
||||||
class RemoteImageCacheManager extends CacheManager with ImageCacheManager {
|
class RemoteImageCacheManager extends CacheManager {
|
||||||
static const key = 'remoteImageCacheKey';
|
static const key = 'remoteImageCacheKey';
|
||||||
static final RemoteImageCacheManager _instance = RemoteImageCacheManager._();
|
static final RemoteImageCacheManager _instance = RemoteImageCacheManager._();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||||
|
|
||||||
/// The cache manager for thumbnail images [ImmichRemoteThumbnailProvider]
|
/// The cache manager for thumbnail images [ImmichRemoteThumbnailProvider]
|
||||||
class ThumbnailImageCacheManager extends CacheManager with ImageCacheManager {
|
class ThumbnailImageCacheManager extends CacheManager {
|
||||||
static const key = 'thumbnailImageCacheKey';
|
static const key = 'thumbnailImageCacheKey';
|
||||||
static final ThumbnailImageCacheManager _instance =
|
static final ThumbnailImageCacheManager _instance =
|
||||||
ThumbnailImageCacheManager._();
|
ThumbnailImageCacheManager._();
|
||||||
|
|
|
@ -10,7 +10,6 @@ import 'package:immich_mobile/shared/models/asset.dart';
|
||||||
import 'package:photo_manager/photo_manager.dart';
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
|
|
||||||
/// The local image provider for an asset
|
/// The local image provider for an asset
|
||||||
/// Only viable
|
|
||||||
class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||||
final Asset asset;
|
final Asset asset;
|
||||||
|
|
||||||
|
@ -94,9 +93,12 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
if (other is! ImmichLocalImageProvider) return false;
|
|
||||||
if (identical(this, other)) return true;
|
if (identical(this, other)) return true;
|
||||||
return asset == other.asset;
|
if (other is ImmichLocalImageProvider) {
|
||||||
|
return asset == other.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ImmichRemoteImageProvider
|
||||||
final String assetId;
|
final String assetId;
|
||||||
|
|
||||||
/// The image cache manager
|
/// The image cache manager
|
||||||
final ImageCacheManager? cacheManager;
|
final CacheManager? cacheManager;
|
||||||
|
|
||||||
ImmichRemoteImageProvider({
|
ImmichRemoteImageProvider({
|
||||||
required this.assetId,
|
required this.assetId,
|
||||||
|
@ -66,7 +66,7 @@ class ImmichRemoteImageProvider
|
||||||
// Streams in each stage of the image as we ask for it
|
// Streams in each stage of the image as we ask for it
|
||||||
Stream<ui.Codec> _codec(
|
Stream<ui.Codec> _codec(
|
||||||
ImmichRemoteImageProvider key,
|
ImmichRemoteImageProvider key,
|
||||||
ImageCacheManager cache,
|
CacheManager cache,
|
||||||
ImageDecoderCallback decode,
|
ImageDecoderCallback decode,
|
||||||
StreamController<ImageChunkEvent> chunkEvents,
|
StreamController<ImageChunkEvent> chunkEvents,
|
||||||
) async* {
|
) async* {
|
||||||
|
|
|
@ -22,7 +22,7 @@ class ImmichRemoteThumbnailProvider
|
||||||
final int? width;
|
final int? width;
|
||||||
|
|
||||||
/// The image cache manager
|
/// The image cache manager
|
||||||
final ImageCacheManager? cacheManager;
|
final CacheManager? cacheManager;
|
||||||
|
|
||||||
ImmichRemoteThumbnailProvider({
|
ImmichRemoteThumbnailProvider({
|
||||||
required this.assetId,
|
required this.assetId,
|
||||||
|
@ -55,7 +55,7 @@ class ImmichRemoteThumbnailProvider
|
||||||
// Streams in each stage of the image as we ask for it
|
// Streams in each stage of the image as we ask for it
|
||||||
Stream<ui.Codec> _codec(
|
Stream<ui.Codec> _codec(
|
||||||
ImmichRemoteThumbnailProvider key,
|
ImmichRemoteThumbnailProvider key,
|
||||||
ImageCacheManager cache,
|
CacheManager cache,
|
||||||
ImageDecoderCallback decode,
|
ImageDecoderCallback decode,
|
||||||
) async* {
|
) async* {
|
||||||
// Load a preview to the chunk events
|
// Load a preview to the chunk events
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import 'package:flutter/painting.dart';
|
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_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_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
|
/// [ImageCache] that uses two caches for small and large images
|
||||||
/// so that a single large image does not evict all small iamges
|
/// so that a single large image does not evict all small iamges
|
||||||
final class CustomImageCache implements ImageCache {
|
final class CustomImageCache implements ImageCache {
|
||||||
final _small = ImageCache();
|
final _small = ImageCache();
|
||||||
final _large = ImageCache();
|
final _large = ImageCache()..maximumSize = 5; // Maximum 5 images
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get maximumSize => _small.maximumSize + _large.maximumSize;
|
int get maximumSize => _small.maximumSize + _large.maximumSize;
|
||||||
|
@ -33,6 +35,8 @@ final class CustomImageCache implements ImageCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the cache for the given key
|
/// 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) =>
|
ImageCache _cacheForKey(Object key) =>
|
||||||
(key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
|
(key is ImmichLocalImageProvider || key is ImmichRemoteImageProvider)
|
||||||
? _large
|
? _large
|
||||||
|
|
Loading…
Reference in a new issue