mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00: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
9 changed files with 39 additions and 15 deletions
|
|
@ -315,7 +315,12 @@ run = [
|
||||||
alias = "mobile:codegen"
|
alias = "mobile:codegen"
|
||||||
description = "Execute build_runner to auto-generate dart code"
|
description = "Execute build_runner to auto-generate dart code"
|
||||||
dir = "mobile"
|
dir = "mobile"
|
||||||
sources = ["pubspec.yaml", "build.yaml", "lib/**/*.dart"]
|
sources = [
|
||||||
|
"pubspec.yaml",
|
||||||
|
"build.yaml",
|
||||||
|
"lib/**/*.dart",
|
||||||
|
"infrastructure/**/*.drift",
|
||||||
|
]
|
||||||
outputs = { auto = true }
|
outputs = { auto = true }
|
||||||
run = "dart run build_runner build --delete-conflicting-outputs"
|
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(
|
(e) => LocalAlbum(
|
||||||
id: e.id,
|
id: e.id,
|
||||||
name: e.name,
|
name: e.name,
|
||||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt) ?? DateTime.now(),
|
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt, isUtc: true) ?? DateTime.timestamp(),
|
||||||
assetCount: e.assetCount,
|
assetCount: e.assetCount,
|
||||||
),
|
),
|
||||||
).toList();
|
).toList();
|
||||||
|
|
@ -296,8 +296,8 @@ extension on Iterable<PlatformAsset> {
|
||||||
name: e.name,
|
name: e.name,
|
||||||
checksum: null,
|
checksum: null,
|
||||||
type: AssetType.values.elementAtOrNull(e.type) ?? AssetType.other,
|
type: AssetType.values.elementAtOrNull(e.type) ?? AssetType.other,
|
||||||
createdAt: tryFromSecondsSinceEpoch(e.createdAt) ?? DateTime.now(),
|
createdAt: tryFromSecondsSinceEpoch(e.createdAt, isUtc: true) ?? DateTime.timestamp(),
|
||||||
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt) ?? DateTime.now(),
|
updatedAt: tryFromSecondsSinceEpoch(e.updatedAt, isUtc: true) ?? DateTime.timestamp(),
|
||||||
width: e.width,
|
width: e.width,
|
||||||
height: e.height,
|
height: e.height,
|
||||||
durationInSeconds: e.durationInSeconds,
|
durationInSeconds: e.durationInSeconds,
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 11;
|
int get schemaVersion => 12;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MigrationStrategy get migration => MigrationStrategy(
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
|
|
@ -159,6 +159,25 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||||
from10To11: (m, v11) async {
|
from10To11: (m, v11) async {
|
||||||
await m.addColumn(v11.localAlbumAssetEntity, v11.localAlbumAssetEntity.marker_);
|
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) {
|
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);
|
return TimeBucket(date: date, assetCount: row.assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(dateExp)]);
|
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -199,7 +199,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -328,7 +328,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(dateExp)]);
|
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -399,7 +399,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(dateExp)]);
|
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -463,7 +463,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(dateExp)]);
|
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -520,7 +520,7 @@ class DriftTimelineRepository extends DriftDatabaseRepository {
|
||||||
..orderBy([OrderingTerm.desc(dateExp)]);
|
..orderBy([OrderingTerm.desc(dateExp)]);
|
||||||
|
|
||||||
return query.map((row) {
|
return query.map((row) {
|
||||||
final timeline = row.read(dateExp)!.dateFmt(groupBy);
|
final timeline = row.read(dateExp)!.truncateDate(groupBy);
|
||||||
final assetCount = row.read(assetCountExp)!;
|
final assetCount = row.read(assetCountExp)!;
|
||||||
return TimeBucket(date: timeline, assetCount: assetCount);
|
return TimeBucket(date: timeline, assetCount: assetCount);
|
||||||
}).watch();
|
}).watch();
|
||||||
|
|
@ -586,7 +586,7 @@ extension on Expression<DateTime> {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on String {
|
extension on String {
|
||||||
DateTime dateFmt(GroupAssetsBy groupBy) {
|
DateTime truncateDate(GroupAssetsBy groupBy) {
|
||||||
final format = switch (groupBy) {
|
final format = switch (groupBy) {
|
||||||
GroupAssetsBy.day || GroupAssetsBy.auto => "y-M-d",
|
GroupAssetsBy.day || GroupAssetsBy.auto => "y-M-d",
|
||||||
GroupAssetsBy.month => "y-M",
|
GroupAssetsBy.month => "y-M",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const int _maxMillisecondsSinceEpoch = 8640000000000000; // 275760-09-13
|
const int _maxMillisecondsSinceEpoch = 8640000000000000; // 275760-09-13
|
||||||
const int _minMillisecondsSinceEpoch = -62135596800000; // 0001-01-01
|
const int _minMillisecondsSinceEpoch = -62135596800000; // 0001-01-01
|
||||||
|
|
||||||
DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch) {
|
DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch, {bool isUtc = false}) {
|
||||||
if (secondsSinceEpoch == null) {
|
if (secondsSinceEpoch == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return DateTime.fromMillisecondsSinceEpoch(milliSeconds);
|
return DateTime.fromMillisecondsSinceEpoch(milliSeconds, isUtc: isUtc);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
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 a new issue