Skip to content

Commit 0b81a49

Browse files
EinTonialextran1502
authored andcommitted
perf(mobile): remove load of thumbnails in the image provider (immich-app#17773)
Remove loading of thumbnail in the image provider * Removed the load of the thumbnail from the local and remote image provider as they shall provide the image, not the thumbnail. The thumbnail gets provided by the thumbnail provider. * The thumbnail provider is used as the loadingBuilder and the image provider as the imageProvider. Therefore loading the thumbnail in the image provider loads it a second time which is completely redundant, uses precious time and yields no results. Co-authored-by: Alex <[email protected]>
1 parent eb5cbbd commit 0b81a49

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

mobile/lib/providers/image/immich_local_image_provider.dart

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,50 +53,35 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
5353
ImageDecoderCallback decode,
5454
StreamController<ImageChunkEvent> chunkEvents,
5555
) async* {
56-
ui.ImmutableBuffer? buffer;
5756
try {
5857
final local = asset.local;
5958
if (local == null) {
6059
throw StateError('Asset ${asset.fileName} has no local data');
6160
}
6261

63-
var thumbBytes = await local
64-
.thumbnailDataWithSize(const ThumbnailSize.square(256), quality: 80);
65-
if (thumbBytes == null) {
66-
throw StateError("Loading thumbnail for ${asset.fileName} failed");
67-
}
68-
buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
69-
thumbBytes = null;
70-
yield await decode(buffer);
71-
buffer = null;
72-
7362
switch (asset.type) {
7463
case AssetType.image:
7564
final File? file = await local.originFile;
7665
if (file == null) {
7766
throw StateError("Opening file for asset ${asset.fileName} failed");
7867
}
79-
buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
68+
final buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
8069
yield await decode(buffer);
81-
buffer = null;
8270
break;
8371
case AssetType.video:
8472
final size = ThumbnailSize(width.ceil(), height.ceil());
85-
thumbBytes = await local.thumbnailDataWithSize(size);
73+
final thumbBytes = await local.thumbnailDataWithSize(size);
8674
if (thumbBytes == null) {
8775
throw StateError("Failed to load preview for ${asset.fileName}");
8876
}
89-
buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
90-
thumbBytes = null;
77+
final buffer = await ui.ImmutableBuffer.fromUint8List(thumbBytes);
9178
yield await decode(buffer);
92-
buffer = null;
9379
break;
9480
default:
9581
throw StateError('Unsupported asset type ${asset.type}');
9682
}
9783
} catch (error, stack) {
9884
log.severe('Error loading local image ${asset.fileName}', error, stack);
99-
buffer?.dispose();
10085
} finally {
10186
chunkEvents.close();
10287
}

mobile/lib/providers/image/immich_remote_image_provider.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,13 @@ class ImmichRemoteImageProvider
5757
AppSettingsEnum.loadOriginal.defaultValue,
5858
);
5959

60-
/// Whether to load the preview thumbnail first or not
61-
bool get _loadPreview => Store.get(
62-
AppSettingsEnum.loadPreview.storeKey,
63-
AppSettingsEnum.loadPreview.defaultValue,
64-
);
65-
6660
// Streams in each stage of the image as we ask for it
6761
Stream<ui.Codec> _codec(
6862
ImmichRemoteImageProvider key,
6963
CacheManager cache,
7064
ImageDecoderCallback decode,
7165
StreamController<ImageChunkEvent> chunkEvents,
7266
) async* {
73-
// Load a preview to the chunk events
74-
if (_loadPreview) {
75-
final preview = getThumbnailUrlForRemoteId(
76-
key.assetId,
77-
type: api.AssetMediaSize.thumbnail,
78-
);
79-
80-
yield await ImageLoader.loadImageFromCache(
81-
preview,
82-
cache: cache,
83-
decode: decode,
84-
chunkEvents: chunkEvents,
85-
);
86-
}
87-
8867
// Load the higher resolution version of the image
8968
final url = getThumbnailUrlForRemoteId(
9069
key.assetId,

0 commit comments

Comments
 (0)