Skip to content

Commit

Permalink
feat(mobile): upload image assets before videos (immich-app#3872)
Browse files Browse the repository at this point in the history
* feat(mobile): upload image assets before videos

* mobile: sort by creation date before uploading assets
  • Loading branch information
shenlong-tanwen authored Aug 27, 2023
1 parent cb39134 commit 912a13e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mobile/lib/modules/backup/services/backup.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,18 @@ class BackupService {
bool anyErrors = false;
final List<String> duplicatedAssetIds = [];

for (var entity in assetList) {
// Upload images before video assets
// these are further sorted by using their creation date so the upload goes as follows
// older images -> latest images -> older videos -> latest videos
List<AssetEntity> sortedAssets = assetList.sorted(
(a, b) {
final cmp = a.typeInt - b.typeInt;
if (cmp != 0) return cmp;
return a.createDateTime.compareTo(b.createDateTime);
},
);

for (var entity in sortedAssets) {
try {
if (entity.type == AssetType.video) {
file = await entity.originFile;
Expand Down Expand Up @@ -248,7 +259,8 @@ class BackupService {

req.fields['deviceAssetId'] = entity.id;
req.fields['deviceId'] = deviceId;
req.fields['fileCreatedAt'] = entity.createDateTime.toUtc().toIso8601String();
req.fields['fileCreatedAt'] =
entity.createDateTime.toUtc().toIso8601String();
req.fields['fileModifiedAt'] =
entity.modifiedDateTime.toUtc().toIso8601String();
req.fields['isFavorite'] = entity.isFavorite.toString();
Expand Down

0 comments on commit 912a13e

Please sign in to comment.