From 8a421eb77892e5dd567cc9e2e25cf9f5a7111b7d Mon Sep 17 00:00:00 2001 From: Azsde Date: Wed, 13 Sep 2023 17:32:06 +0200 Subject: [PATCH] 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 --- .../backup/providers/backup.provider.dart | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/mobile/lib/modules/backup/providers/backup.provider.dart b/mobile/lib/modules/backup/providers/backup.provider.dart index 2aacf49be..3e226d817 100644 --- a/mobile/lib/modules/backup/providers/backup.provider.dart +++ b/mobile/lib/modules/backup/providers/backup.provider.dart @@ -217,24 +217,19 @@ class BackupNotifier extends StateNotifier { 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);