1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

feat(mobile): faster image loader (#8140)

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Fynn Petersen-Frey 2024-03-21 17:51:03 +01:00 committed by GitHub
parent 5ef6215546
commit 1abb0bdae8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,8 +16,6 @@ class ImageLoader {
required ImageCacheManager cache, required ImageCacheManager cache,
required ImageDecoderCallback decode, required ImageDecoderCallback decode,
StreamController<ImageChunkEvent>? chunkEvents, StreamController<ImageChunkEvent>? chunkEvents,
int? height,
int? width,
}) async { }) async {
final headers = { final headers = {
'x-immich-user-token': Store.get(StoreKey.accessToken), 'x-immich-user-token': Store.get(StoreKey.accessToken),
@ -25,10 +23,8 @@ class ImageLoader {
final stream = cache.getImageFile( final stream = cache.getImageFile(
uri, uri,
withProgress: true, withProgress: chunkEvents != null,
headers: headers, headers: headers,
maxHeight: height,
maxWidth: width,
); );
await for (final result in stream) { await for (final result in stream) {
@ -40,13 +36,9 @@ class ImageLoader {
expectedTotalBytes: result.totalSize, expectedTotalBytes: result.totalSize,
), ),
); );
} } else if (result is FileInfo) {
if (result is FileInfo) {
// We have the file // We have the file
final file = result.file; final buffer = await ui.ImmutableBuffer.fromFilePath(result.file.path);
final bytes = await file.readAsBytes();
final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
final decoded = await decode(buffer); final decoded = await decode(buffer);
return decoded; return decoded;
} }