mirror of
https://github.com/zebrajr/immich.git
synced 2025-12-06 00:20:20 +01:00
fix: merged timeline orderby localtime (#22371)
* chore: refactor dateFmt to truncateDate * fix: merged timeline orderby localtime --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
bea116e1b9
commit
fea5e6783c
|
|
@ -315,7 +315,12 @@ run = [
|
|||
alias = "mobile:codegen"
|
||||
description = "Execute build_runner to auto-generate dart code"
|
||||
dir = "mobile"
|
||||
sources = ["pubspec.yaml", "build.yaml", "lib/**/*.dart"]
|
||||
sources = [
|
||||
"pubspec.yaml",
|
||||
"build.yaml",
|
||||
"lib/**/*.dart",
|
||||
"infrastructure/**/*.drift",
|
||||
]
|
||||
outputs = { auto = true }
|
||||
run = "dart run build_runner build --delete-conflicting-outputs"
|
||||
|
||||
|
|
|
|||
BIN
mobile/drift_schemas/main/drift_schema_v12.json
generated
Normal file
BIN
mobile/drift_schemas/main/drift_schema_v12.json
generated
Normal file
Binary file not shown.
|
|
@ -281,7 +281,7 @@ extension on Iterable<PlatformAlbum> {
|
|||
(e) => LocalAlbum(
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt) ?? DateTime.now(),
|
||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt, isUtc: true) ?? DateTime.timestamp(),
|
||||
assetCount: e.assetCount,
|
||||
),
|
||||
).toList();
|
||||
|
|
@ -296,8 +296,8 @@ extension on Iterable<PlatformAsset> {
|
|||
name: e.name,
|
||||
checksum: null,
|
||||
type: AssetType.values.elementAtOrNull(e.type) ?? AssetType.other,
|
||||
createdAt: tryFromSecondsSinceEpoch(e.createdAt) ?? DateTime.now(),
|
||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt) ?? DateTime.now(),
|
||||
createdAt: tryFromSecondsSinceEpoch(e.createdAt, isUtc: true) ?? DateTime.timestamp(),
|
||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt, isUtc: true) ?? DateTime.timestamp(),
|
||||
width: e.width,
|
||||
height: e.height,
|
||||
durationInSeconds: e.durationInSeconds,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class Drift extends $Drift implements IDatabaseRepository {
|
|||
}
|
||||
|
||||
@override
|
||||
int get schemaVersion => 11;
|
||||
int get schemaVersion => 12;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
|
|
@ -159,6 +159,25 @@ class Drift extends $Drift implements IDatabaseRepository {
|
|||
from10To11: (m, v11) async {
|
||||
await m.addColumn(v11.localAlbumAssetEntity, v11.localAlbumAssetEntity.marker_);
|
||||
},
|
||||
from11To12: (m, v12) async {
|
||||
final localToUTCMapping = {
|
||||
v12.localAssetEntity: [v12.localAssetEntity.createdAt, v12.localAssetEntity.updatedAt],
|
||||
v12.localAlbumEntity: [v12.localAlbumEntity.updatedAt],
|
||||
};
|
||||
|
||||
for (final entry in localToUTCMapping.entries) {
|
||||
final table = entry.key;
|
||||
await m.alterTable(
|
||||
TableMigration(
|
||||
table,
|
||||
columnTransformer: {
|
||||
for (final column in entry.value)
|
||||
column: column.modify(const DateTimeModifier.utc()).strftime('%Y-%m-%dT%H:%M:%fZ'),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -43,7 +43,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
}
|
||||
|
||||
return _db.mergedAssetDrift.mergedBucket(userIds: userIds, groupBy: groupBy.index).map((row) {
|
||||
final date = row.bucketDate.dateFmt(groupBy);
|
||||
final date = row.bucketDate.truncateDate(groupBy);
|
||||
return TimeBucket(date: date, assetCount: row.assetCount);
|
||||
}).watch();
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -199,7 +199,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
}
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -328,7 +328,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -399,7 +399,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -463,7 +463,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -520,7 +520,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
|||
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||
|
||||
return query.map((row) {
|
||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
||||
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||
}).watch();
|
||||
|
|
@ -586,7 +586,7 @@ extension on Expression<DateTime> {
|
|||
}
|
||||
|
||||
extension on String {
|
||||
DateTime dateFmt(GroupAssetsBy groupBy) {
|
||||
DateTime truncateDate(GroupAssetsBy groupBy) {
|
||||
final format = switch (groupBy) {
|
||||
GroupAssetsBy.day || GroupAssetsBy.auto => "y-M-d",
|
||||
GroupAssetsBy.month => "y-M",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const int _maxMillisecondsSinceEpoch = 8640000000000000; // 275760-09-13
|
||||
const int _minMillisecondsSinceEpoch = -62135596800000; // 0001-01-01
|
||||
|
||||
DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch) {
|
||||
DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch, {bool isUtc = false}) {
|
||||
if (secondsSinceEpoch == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch) {
|
|||
}
|
||||
|
||||
try {
|
||||
return DateTime.fromMillisecondsSinceEpoch(milliSeconds);
|
||||
return DateTime.fromMillisecondsSinceEpoch(milliSeconds, isUtc: isUtc);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
BIN
mobile/test/drift/main/generated/schema.dart
generated
BIN
mobile/test/drift/main/generated/schema.dart
generated
Binary file not shown.
BIN
mobile/test/drift/main/generated/schema_v12.dart
generated
Normal file
BIN
mobile/test/drift/main/generated/schema_v12.dart
generated
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user