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:
parent
14e681c954
commit
8a421eb778
1 changed files with 13 additions and 18 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue