mirror of
https://github.com/immich-app/immich.git
synced 2026-03-26 20:00:44 +03:00
perf(mobile): optimized album sorting (#25179)
* perf(mobile): optimized album sorting * refactor: add index & sql query * fix: migration * refactor: enum, ordering & list * test: update album service tests * chore: fix enums broken during merging main * chore: remove unnecessary tests * test: add tests for getSortedAlbumIds * test: added back stubs in service test
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:immich_mobile/constants/enums.dart';
|
||||
import 'package:immich_mobile/domain/models/album/album.model.dart';
|
||||
import 'package:immich_mobile/domain/services/remote_album.service.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/remote_album.repository.dart';
|
||||
@@ -13,38 +14,6 @@ void main() {
|
||||
late DriftRemoteAlbumRepository mockRemoteAlbumRepo;
|
||||
late DriftAlbumApiRepository mockAlbumApiRepo;
|
||||
|
||||
setUp(() {
|
||||
mockRemoteAlbumRepo = MockRemoteAlbumRepository();
|
||||
mockAlbumApiRepo = MockDriftAlbumApiRepository();
|
||||
sut = RemoteAlbumService(mockRemoteAlbumRepo, mockAlbumApiRepo);
|
||||
|
||||
when(() => mockRemoteAlbumRepo.getNewestAssetTimestamp(any())).thenAnswer((invocation) {
|
||||
// Simulate a timestamp for the newest asset in the album
|
||||
final albumID = invocation.positionalArguments[0] as String;
|
||||
|
||||
if (albumID == '1') {
|
||||
return Future.value(DateTime(2023, 1, 1));
|
||||
} else if (albumID == '2') {
|
||||
return Future.value(DateTime(2023, 2, 1));
|
||||
}
|
||||
|
||||
return Future.value(DateTime.fromMillisecondsSinceEpoch(0));
|
||||
});
|
||||
|
||||
when(() => mockRemoteAlbumRepo.getOldestAssetTimestamp(any())).thenAnswer((invocation) {
|
||||
// Simulate a timestamp for the oldest asset in the album
|
||||
final albumID = invocation.positionalArguments[0] as String;
|
||||
|
||||
if (albumID == '1') {
|
||||
return Future.value(DateTime(2019, 1, 1));
|
||||
} else if (albumID == '2') {
|
||||
return Future.value(DateTime(2019, 2, 1));
|
||||
}
|
||||
|
||||
return Future.value(DateTime.fromMillisecondsSinceEpoch(0));
|
||||
});
|
||||
});
|
||||
|
||||
final albumA = RemoteAlbum(
|
||||
id: '1',
|
||||
name: 'Album A',
|
||||
@@ -73,6 +42,21 @@ void main() {
|
||||
isShared: false,
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
mockRemoteAlbumRepo = MockRemoteAlbumRepository();
|
||||
mockAlbumApiRepo = MockDriftAlbumApiRepository();
|
||||
|
||||
when(
|
||||
() => mockRemoteAlbumRepo.getSortedAlbumIds(any(), aggregation: AssetDateAggregation.end),
|
||||
).thenAnswer((_) async => ['1', '2']);
|
||||
|
||||
when(
|
||||
() => mockRemoteAlbumRepo.getSortedAlbumIds(any(), aggregation: AssetDateAggregation.start),
|
||||
).thenAnswer((_) async => ['1', '2']);
|
||||
|
||||
sut = RemoteAlbumService(mockRemoteAlbumRepo, mockAlbumApiRepo);
|
||||
});
|
||||
|
||||
group('sortAlbums', () {
|
||||
test('should sort correctly based on name', () async {
|
||||
final albums = [albumB, albumA];
|
||||
|
||||
Reference in New Issue
Block a user