Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): revert cache fixes (#17786)

Alex0986a71ce3df
diff --git a/mobile/lib/providers/image/immich_local_image_provider.dart b/mobile/lib/providers/image/immich_local_image_provider.dart
index 34c3c94ded..36fd3334b9 100644
--- a/mobile/lib/providers/image/immich_local_image_provider.dart
+++ b/mobile/lib/providers/image/immich_local_image_provider.dart
@@ -106,12 +106,12 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other is ImmichLocalImageProvider) {
- return asset.id == other.asset.id;
+ return asset == other.asset;
}
return false;
}
@override
- int get hashCode => asset.id.hashCode;
+ int get hashCode => asset.hashCode;
}
diff --git a/mobile/lib/providers/image/immich_local_thumbnail_provider.dart b/mobile/lib/providers/image/immich_local_thumbnail_provider.dart
index 9ccb127626..69cdb105c0 100644
--- a/mobile/lib/providers/image/immich_local_thumbnail_provider.dart
+++ b/mobile/lib/providers/image/immich_local_thumbnail_provider.dart
@@ -2,14 +2,11 @@ import 'dart:async';
import 'dart:ui' as ui;
import 'package:cached_network_image/cached_network_image.dart';
-import 'package:flutter_cache_manager/flutter_cache_manager.dart';
-import 'package:immich_mobile/providers/image/cache/thumbnail_image_cache_manager.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:photo_manager/photo_manager.dart' show ThumbnailSize;
-import 'package:logging/logging.dart';
/// The local image provider for an asset
/// Only viable
@@ -18,14 +15,11 @@ class ImmichLocalThumbnailProvider
final Asset asset;
final int height;
final int width;
- final CacheManager? cacheManager;
- final Logger log = Logger("ImmichLocalThumbnailProvider");
ImmichLocalThumbnailProvider({
required this.asset,
this.height = 256,
this.width = 256,
- this.cacheManager,
}) : assert(asset.local != null, 'Only usable when asset.local is set');
/// Converts an [ImageProvider]'s settings plus an [ImageConfiguration] to a key
@@ -42,10 +36,11 @@ class ImmichLocalThumbnailProvider
ImmichLocalThumbnailProvider key,
ImageDecoderCallback decode,
) {
- final cache = cacheManager ?? ThumbnailImageCacheManager();
+ final chunkEvents = StreamController<ImageChunkEvent>();
return MultiImageStreamCompleter(
- codec: _codec(key.asset, cache, decode),
+ codec: _codec(key.asset, decode, chunkEvents),
scale: 1.0,
+ chunkEvents: chunkEvents.stream,
informationCollector: () sync* {
yield ErrorDescription(asset.fileName);
},
@@ -55,48 +50,43 @@ class ImmichLocalThumbnailProvider
// Streams in each stage of the image as we ask for it
Stream<ui.Codec> _codec(
Asset key,
- CacheManager cache,
ImageDecoderCallback decode,
+ StreamController<ImageChunkEvent> chunkEvents,
) async* {
- final cacheKey = '${key.id}_${width}x$height';
- final fileFromCache = await cache.getFileFromCache(cacheKey);
- if (fileFromCache != null) {
- try {
- final buffer =
- await ui.ImmutableBuffer.fromFilePath(fileFromCache.file.path);
- final codec = await decode(buffer);
- yield codec;
- return;
- } catch (error) {
- log.severe('Found thumbnail in cache, but loading it failed', error);
- }
+ // Load a small thumbnail
+ final thumbBytes = await asset.local?.thumbnailDataWithSize(
+ const ThumbnailSize.square(32),
+ quality: 75,
+ );
+ if (thumbBytes != null) {
+ final buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
+ final codec = await decode(buffer);
+ yield codec;
+ } else {
+ debugPrint("Loading thumb for ${asset.fileName} failed");
}
- final thumbnailBytes = await asset.local?.thumbnailDataWithSize(
- ThumbnailSize(width, height),
- quality: 80,
- );
- if (thumbnailBytes == null) {
+ final normalThumbBytes =
+ await asset.local?.thumbnailDataWithSize(ThumbnailSize(width, height));
+ if (normalThumbBytes == null) {
throw StateError(
"Loading thumb for local photo ${asset.fileName} failed",
);
}
- final buffer = await ui.ImmutableBuffer.fromUint8List(thumbnailBytes);
+ final buffer = await ui.ImmutableBuffer.fromUint8List(normalThumbBytes);
final codec = await decode(buffer);
yield codec;
- await cache.putFile(cacheKey, thumbnailBytes);
+
+ chunkEvents.close();
}
@override
bool operator ==(Object other) {
+ if (other is! ImmichLocalThumbnailProvider) return false;
if (identical(this, other)) return true;
- if (other is ImmichLocalThumbnailProvider) {
- return asset.id == other.asset.id;
- }
-
- return false;
+ return asset == other.asset;
}
@override
- int get hashCode => asset.id.hashCode;
+ int get hashCode => asset.hashCode;
}