mirror of
https://github.com/samsonjs/immich.git
synced 2026-03-25 09:15:56 +00:00
fix: local date time group fall back (#26110)
* fix: local date time group fall back * remove else clause
This commit is contained in:
parent
8c8b11f80c
commit
adfb003d03
3 changed files with 59 additions and 2 deletions
|
|
@ -90,8 +90,14 @@ FROM
|
|||
(
|
||||
SELECT
|
||||
CASE
|
||||
WHEN :group_by = 0 THEN STRFTIME('%Y-%m-%d', rae.local_date_time)
|
||||
WHEN :group_by = 1 THEN STRFTIME('%Y-%m', rae.local_date_time)
|
||||
WHEN :group_by = 0 THEN COALESCE(
|
||||
STRFTIME('%Y-%m-%d', rae.local_date_time),
|
||||
STRFTIME('%Y-%m-%d', rae.created_at, 'localtime')
|
||||
)
|
||||
WHEN :group_by = 1 THEN COALESCE(
|
||||
STRFTIME('%Y-%m', rae.local_date_time),
|
||||
STRFTIME('%Y-%m', rae.created_at, 'localtime')
|
||||
)
|
||||
END as bucket_date
|
||||
FROM
|
||||
remote_asset_entity rae
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -0,0 +1,51 @@
|
|||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/timeline.model.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||
|
||||
void main() {
|
||||
late Drift db;
|
||||
|
||||
setUp(() {
|
||||
db = Drift(DatabaseConnection(NativeDatabase.memory(), closeStreamsSynchronously: true));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('mergedBucket falls back to createdAt when localDateTime is null', () async {
|
||||
const userId = 'user-1';
|
||||
final createdAt = DateTime(2024, 1, 1, 12);
|
||||
|
||||
await db
|
||||
.into(db.userEntity)
|
||||
.insert(UserEntityCompanion.insert(id: userId, email: 'user-1@test.dev', name: 'User 1'));
|
||||
|
||||
await db
|
||||
.into(db.remoteAssetEntity)
|
||||
.insert(
|
||||
RemoteAssetEntityCompanion.insert(
|
||||
id: 'asset-1',
|
||||
name: 'asset-1.jpg',
|
||||
type: AssetType.image,
|
||||
checksum: 'checksum-1',
|
||||
ownerId: userId,
|
||||
visibility: AssetVisibility.timeline,
|
||||
createdAt: Value(createdAt),
|
||||
updatedAt: Value(createdAt),
|
||||
localDateTime: const Value(null),
|
||||
),
|
||||
);
|
||||
|
||||
final buckets = await db.mergedAssetDrift.mergedBucket(groupBy: GroupAssetsBy.day.index, userIds: [userId]).get();
|
||||
|
||||
expect(buckets, hasLength(1));
|
||||
expect(buckets.single.assetCount, 1);
|
||||
expect(buckets.single.bucketDate, isNotEmpty);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue