1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

fix (mobile): Fix slow album thumbnail generation for album picker (#3905)

* [BUGFIX] Fix slow album thumbnail generation

When generating the thumbnail of an album, all of the pictures of the
album are retrieved but only the first picture of the album is used.

Retrieving all of the pictures of the album at once can cause huge performance
issues on large albums.

Since only the first picture is used to generate the thumbnail, this commit
uses the getAssetListPaged method instead of getAssetListRange, effectively
retrieving only the first picture of the album.

* [DEVMINOR] Remove unecessary check

As we already check for the number of assets in the album, when
fetching assets using `album.getAssetListPaged` the returned result
won't be empty.

---------

Co-authored-by: Azsde <aelkaim@pixium-vision.com>
This commit is contained in:
Azsde 2023-09-13 17:32:06 +02:00 committed by GitHub
parent 14e681c954
commit 8a421eb778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -217,24 +217,19 @@ class BackupNotifier extends StateNotifier<BackUpState> {
final assetCountInAlbum = await album.assetCountAsync;
if (assetCountInAlbum > 0) {
final assetList =
await album.getAssetListRange(start: 0, end: assetCountInAlbum);
if (assetList.isNotEmpty) {
final thumbnailAsset = assetList.first;
try {
final thumbnailData = await thumbnailAsset
.thumbnailDataWithSize(const ThumbnailSize(512, 512));
availableAlbum =
availableAlbum.copyWith(thumbnailData: thumbnailData);
} catch (e, stack) {
log.severe(
"Failed to get thumbnail for album ${album.name}",
e.toString(),
stack,
);
}
final assetList = await album.getAssetListPaged(page: 0, size: 1);
final thumbnailAsset = assetList.first;
try {
final thumbnailData = await thumbnailAsset
.thumbnailDataWithSize(const ThumbnailSize(512, 512));
availableAlbum =
availableAlbum.copyWith(thumbnailData: thumbnailData);
} catch (e, stack) {
log.severe(
"Failed to get thumbnail for album ${album.name}",
e.toString(),
stack,
);
}
availableAlbums.add(availableAlbum);