Android app take forever to list albums
Hello everyone, I have set up my server and am having issues with the app, it takes forever to load the '' albums '', I managed to have them show up once but I cannot see them anymore.
Does anyone have a solution?

110 Replies
which phone model do you have? How many photos/videos do you have on your phone? Can you provide the mobile app log?
I have a Galaxy Z Fold 4, I have quite a large number of photo/videos in the DCIM folder (3172 to be exact)
that is not large by any mean, hmm, not sure what is happening there. Can you go into the app setting > advanced > prefer remote images, turn it on and then try again
Alright, for the logs do you need ADB logs ?
Or the one from the app directly ?
No just the app log from the profile drawer > log
Alright
Do you allow permission to access all photos when you first started the app?
I think so, let me check
Yeah, it has permissions for pictures and videos
Setting "Prefer remote images" doesn't fix the issue
navigate the that album selection page, wait a few second, navigate back to the back up page, wait a few second then back to the selection page, does it work?
Please export the app log and send it here so I can take a look
Still buggy, I'm exporting the logs right now
Hmm I see an error, somehow the app cannot get all the assets from the server, is this a brand new instance?
yes
But I don't see how remote assets can affect local albums from being listed
I am just suspecting, I don't think it is the cause either
I am trying to send a video capture of the issue
Can you try reinstall the app?
Sure
Thank you
From the play store right ?
Great, now the immich app doesn't start at all ๐ฅฒ it is stuck on the immich logo
I'm rebooting my phone
correct
strange
Still stuck even after rebooting
Can you access the server from the web
Yes
Ah, the app finally launched
were you using local IP or dns?
I cleared the storage and the cache so it was not trying to access the server
But I have a reverse proxy to access my immich server
Can you bypass that and access the server with local IP
just to keep everything contained for debugging purposes
Yes
I am accessing via the local IP
And it still struggles to list all albums on my phone

hmm
This is with newly install app and adequate permissions, correct?
Yes
I am suspecting this is specific phone's model issue and without the phone I cannot really debug it. Are you a developer by any chance?
Yes I am
I've worked on AOSP for 6+ years
Do you mind installing the flutter toolchain and run the app under development on your phone to see if it catch any error?
But on the framework part, I have limited experience regarding androids apps but I should be able to figure it out
Alright
it is quite straight forward, here is a guide https://immich.app/docs/developer/setup#mobile-app
Setup | Immich
Environment
let me know if I can assist
Alright, I'm on it
(I'm surprised it doesn't use Android Studio :D)
it does actually ๐ but just for installting drivers
you can run the development environment in vscode entirely
cd immich
oops
Ok so I think I've setup everyhting
What do I need to do to compile the app and get an APK ?
you would run it in development mode
run
flutter doctor
and check the output
I've ran the command : flutter build apk --split-per-abi
It does seem to trigger a build, I don't know if that is the "official" way to do it
Build failed because I don't have the signing key (that's normal)
Run flutter run for debug mode
I launched the same command with --debug and the APK built succesfully
The debug APK behaves the same way
I should type "flutter run" ?
Yes
Alright
Ok
I do have an ADB log output
and the apk launched onto my phone
What do you need from here ?
When you access the album selection page do you see anything logged?
I/ViewRootImpl@9fbccc7MainActivity: ViewPostIme pointer 0
I/ViewRootImpl@9fbccc7MainActivity: ViewPostIme pointer 1
I/flutter (23403): [INFO] [2023-08-29 12:28:25.266535] Found 36 local albums
And then nothing
The logs now show this
( I need to leave for lunch, I'll be back soon)
I'm back
Do you need more logs ?
I/flutter (23403): [INFO] [2023-08-29 12:29:40.495339] Not found albums or assets on the device to backup
Hmm
Are all the albums and photos/videos are on your local device?Yes
( Using an Android emulator it works as expected without any issue)
I am suspecting issue with photo_manager package we use to get the local photos and videos with your device's system API call
I know samsung is famous for doing weird stuff with the Android Framework
yeah pretty strange :/
Do you want me to share my screen or something to try to pinpoint the issue ?
I/flutter (26896): [INFO] [2023-08-29 13:46:33.495851] Found 36 local albums
I do have this log but the app never finishes loading
My friend also has a ZFold 4 and has the exact same issue


After a while they DO show up in the end
That is a really weird behavior
Is it possible to put breakpoints in the code ?
@Alex I don't think the issue comes from the photo_manager package
I've written a really quick and dirty app using flutter
void _test() async {
final PermissionState ps = await PhotoManager.requestPermissionExtend();
if (ps.hasAccess) {
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList();
print(albums);
}
}
And it works instanteanously :
I/flutter (21219): [AssetPathEntity(id: isAll, name: Recent), AssetPathEntity(id: -214169408, name: Instagram), AssetPathEntity(id: -1432612566, name: WhatsApp Video), AssetPathEntity(id: -786583970, name: Reddit), AssetPathEntity(id: 1519174419, name: Messenger), AssetPathEntity(id: 402919108, name: Whatsapp), AssetPathEntity(id: -613830029, name: Twitter), AssetPathEntity(id: 1028075469, name: Screenshots), AssetPathEntity(id: 1331207306, name: Seal), AssetPathEntity(id: -1744159402, name: DSphoto), AssetPathEntity(id: -1183850781, name: PowerDirector), AssetPathEntity(id: 1385037952, name: Screen Recorder), AssetPathEntity(id: -1104308479, name: Twitter), AssetPathEntity(id: -572399359, name: Telegram), AssetPathEntity(id: -680697881, name: WhatsApp Documents), AssetPathEntity(id: 1285198534, name: Facebook), AssetPathEntity(id: 540528482, name: Download), AssetPathEntity(id: -815228101, name: WhatsApp Animated Gifs), AssetPathEntity(id: -1829889111, name: WhatsApp Images), AssetPathEntity(id: 1389444597, name: ), AssetPath
Hmm
perhaps state management issue
but then it would be present on all phone model, correct?

This is from a fresh install, with the initial setup
After the getAssetPathList first call
Albums are correctly detected
( I've put a breakpoint to see the value of the variable)
so for some reason the album aren't render on screen
we can narrow down to the provider that handle render the album
Yeah and the UI is stuck "loading"
Hm.
The issue seems to come from the _getBackupAlbumsInfo function
I've added a log at the end of the function which is printed only after a VERY long time
By the way:
D/flutter (32252): [INFO] [2023-08-29 15:24:30.617169] _getBackupAlbumsInfo takes 97761ms
That's 1m36s to list the albums
I will try to determine which part of the function is taking forever to finish
Well, the thumbnail generation is taking forever ๐
There is known issue with thumbnail generation on some android device reading from the disk
let me find the issue
relevant issue https://github.com/immich-app/immich/issues/834
GitHub
[BUG] Mobile app: Backup settings page takes a long time to load st...
When the mobile app's backup_controller_page is initializing, one of the steps in getting its state involves loading the list of local albums that are present on the device. This is implemented...
Here is another one https://github.com/immich-app/immich/issues/2128
GitHub
[BUG] Slow preview and pictures/video load from device memory ยท Iss...
The bug When loading from memory, the app starts to lag and the time required to load the previews goes to around 10s, 20s at times. It happened as soon as I updated the app to the 1.51.0 version. ...
The issue seems to be related to mine
If you remove the code to get the thumbnail, does it work better?
Let me try
I need to determine which line to comment to still have my albums listed
which file are you looking at right now?
backup.provider.dart
I need to update this line to use a "placeholder" thumbnail
availableAlbum = availableAlbum.copyWith(thumbnailData: thumbnailData);
it is a nullable value, you can remove it

this whole block can be commented out
Alright, testing right now
lol yeah
it works
Instantly
ah nice
ok I can start working on a fix
Here's a log trace when the issue happens, note that I've added those logs:
I/flutter (14796): [INFO] [2023-08-29 15:34:00.648336] AZSDE - Hello before thumbnail
I/flutter (14796): [INFO] [2023-08-29 15:35:08.595915] AZSDE - Hello after thumbnail
It would seem that OpenGLRenderer is trying to do something ?
Let me see if I can pinpoint a little bit more on what is taking so long in this commented block
Thank you for looking into this
it has been an issue for a while
Same issue on my Samsung S23 Snapdragon by the way. @Azsde are you shooting HEIC/HEIF by any chance instead of JPEG? My S23 suffers from this GH issue https://github.com/immich-app/immich/issues/2128 where heic's take really long do display in the timeline (whereas JPEGs are quite fast) (so I use the "use remote assets" workaround). Maybe it is related to this thumbnail generation problem.
GitHub
[BUG] Slow preview and pictures/video load from device memory ยท Iss...
The bug When loading from memory, the app starts to lag and the time required to load the previews goes to around 10s, 20s at times. It happened as soon as I updated the app to the 1.51.0 version. ...
It doesn't seem to be the case as my pictures do have the .jpeg extension ?
Alright, then it's probably not related to heic files ๐
This line seems to be the culprit:
log.info('AZSDE - Before get asset list');
final assetList =
await album.getAssetListRange(start: 0, end: assetCountInAlbum);
log.info('AZSDE - After get asset list');
The logs are showing
I/flutter (24082): [INFO] [2023-08-29 16:00:25.354140] AZSDE - Before get asset list
I/flutter (24082): [INFO] [2023-08-29 16:01:45.543699] AZSDE - After get asset list
1min20s to retrieve the asset list ?! Wow
@Alex I'll update my "hello-world" app to add asset retrieval, I suspect I will have the same issue then
hmm
Yeah, exactly as I suspected
updating my hello world app produces the same issue
The "recent" album on my phone has 36606 pictures
Oh that is quite a lot
The first getAssetListRange call is taking forever
how much storage do you have on your phone?
512Gb
I see
But
sdcard or built-in nvme?
Samsung phones are "stupid"
They have a "recent" album which regroups EVERYTHING
same thing for iOS ๐
That's stupid
Especially that my REAL camera folder
Has only 3172 items
That being said, I don't know if it is "normal" for getAssetListRange to take such a long time, but the issue doesn't seem to be on Immich side
Let me think of a better way to handle this case
thank you for reporting and helping pin down the issue
You're welcome, thank you for such an awesome tool
Maybe a better way to do it
Would be to to only get the first picture directly ?
yeah for that page it would probably work better that way
the calculation still need to happen at some point
I am looking at their documentation
Future<List<AssetEntity>> getAssetListRange({
required int start,
required int end,
}) async {
assert(albumType == 1, 'Only album can request for assets.');
assert(start >= 0, 'The start must be greater than 0.');
assert(end > start, 'The end must be greater than start.');
We can't use this to get a single asset
Since we need to specify a range
From a quick look, they seem to have a getAssetListPaged method
If it is named correctly, it might be the way to go ? As pagination is often used to retrieve larges amounts of data in chunks ?
yeah this makes sense
Another approach would be to exclude the "recent" album
Or at least make it optional
But that doesn't fully resolve the issue
This comes down to UX, some people want to upload everything on their phone, and if they have like 30 albums/folders to choose from, I think it might be bad UX. But a good point regardless, let me contemplate on this
Yeah, I can understand that some people might want this ๐
And as I said, it doesn't cover the case where someone whould have a large amount of assets in an album
I have plan to revamp the whole backup/selection mechanism anyway
so these things can change
the current backup mechanism has been there since the start and it has been working so we are focusing manpower on other issues/features first
Yeah obviously
(I've excluded the recent album but now whatsapp causes a similar issue has it has 30k+ assets ... )
Ok, so IMO, the proper fix for the time being is to use:
final assetList = await album.getAssetListPaged(page: 0, size: 1);
( on another note, I find that the album selection UI is quite laggy ๐ )
Do you want me do to a PR ?
( for the thumbnail issue, not the laggy UI)
yes
thank you
Alright
Tehre you go
GitHub
fix (mobile): Fix slow album thumbnail generation on Android by azs...
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 ca...