This commit is contained in:
Alex 2024-09-11 14:26:36 -05:00
parent e69bcf3f70
commit 4c9a7a7ed5
No known key found for this signature in database
GPG Key ID: 53CD082B3A5E1082
3 changed files with 40 additions and 15 deletions

View File

@ -8,7 +8,6 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/extensions/theme_extensions.dart';
import 'package:immich_mobile/main.dart';
import 'package:immich_mobile/pages/common/large_leading_tile.dart';
import 'package:immich_mobile/providers/album/album_sort_by_options.provider.dart';
import 'package:immich_mobile/providers/album/albumv2.provider.dart';
@ -78,7 +77,11 @@ class AlbumsCollectionPage extends HookConsumerWidget {
return Scaffold(
appBar: AppBar(
title: showImmichAppbar ? null : Text('albums'.tr()),
title: showImmichAppbar
? null
: Text(
"${'albums'.tr()} ${albums.length}",
),
bottom: showImmichAppbar
? const PreferredSize(
preferredSize: Size.fromHeight(0),

View File

@ -27,10 +27,13 @@ class AlbumNotifierV2 extends StateNotifier<List<Album>> {
late final StreamSubscription<List<Album>> _streamSub;
Future<void> refreshAlbums() async {
Future.wait([
_albumService.refreshDeviceAlbums(),
_albumService.refreshAllRemoteAlbums(),
]);
// Future.wait([
// _albumService.refreshDeviceAlbums(),
// _albumService.refreshAllRemoteAlbums(),
// ]);
await _albumService.refreshDeviceAlbums();
await _albumService.refreshRemoteAlbums(isShared: false);
await _albumService.refreshRemoteAlbums(isShared: true);
}
Future<void> getDeviceAlbums() {

View File

@ -175,26 +175,45 @@ class AlbumService {
/// V2
Future<bool> refreshAllRemoteAlbums() async {
if (!_remoteCompleter.isCompleted) {
// guard against concurrent calls
return _remoteCompleter.future;
}
_remoteCompleter = Completer();
final Stopwatch sw = Stopwatch()..start();
bool changes = false;
try {
final [sharedAlbums, ownedAlbums] = await Future.wait([
final albumList = await Future.wait([
_apiService.albumsApi.getAllAlbums(shared: true),
_apiService.albumsApi.getAllAlbums(shared: false),
]);
final List<AlbumResponseDto> allAlbums = [
...sharedAlbums ?? [],
...ownedAlbums ?? [],
];
// for (int i = 0; i < albumList.length; i++) {
// final albums = albumList[i];
// final isShared = i == 1;
// if (albums != null) {
// final hasChange = await _syncService.syncRemoteAlbumsToDb(
// albums,
// isShared: isShared,
// loadDetails: (dto) async => dto.assetCount == dto.assets.length
// ? dto
// : (await _apiService.albumsApi.getAlbumInfo(dto.id)) ?? dto,
// );
print("All albums: ${allAlbums.length}");
debugPrint("refreshAllAlbums took ${sw.elapsedMilliseconds}ms");
return true;
// if (hasChange) {
// changes = true;
// }
// }
// }
} catch (e) {
debugPrint("Error refreshing all albums: $e");
return false;
} finally {
_remoteCompleter.complete(changes);
}
debugPrint("refreshAllRemoteAlbums took ${sw.elapsedMilliseconds}ms");
return changes;
}
Future<Album?> createAlbum(