Skip to content

Commit c5c86d4

Browse files
committed
feat: enhance asset handling to record already processed files and improve duplicate detection
1 parent 1390fbe commit c5c86d4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

app/cmd/upload/run.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,21 @@ func (upCmd *UpCmd) handleAsset(ctx context.Context, a *assets.Asset) error {
319319
a.Close() // Close and clean resources linked to the local asset
320320
}()
321321

322-
// check if the asset is already processed
323-
if !upCmd.localAssets.Add(a.DeviceAssetID()) {
324-
upCmd.app.Jnl().Record(ctx, fileevent.AnalysisLocalDuplicate, fshelper.FSName(a.File.FS(), a.OriginalFileName))
325-
return nil
326-
}
327-
328-
// var status string
322+
// var status stri g
329323
advice, err := upCmd.assetIndex.ShouldUpload(a)
330324
if err != nil {
331325
return err
332326
}
333327

334328
switch advice.Advice {
329+
335330
case NotOnServer: // Upload and manage albums
336331
serverStatus, err := upCmd.uploadAsset(ctx, a)
337332
if err != nil {
338333
return err
339334
}
340335

341-
if serverStatus != "duplicate" {
336+
if serverStatus != immich.StatusDuplicate {
342337
// TODO: current version of Immich doesn't allow to add same tag to an asset already tagged.
343338
// there is no mean to go the list of tagged assets for a given tag.
344339
upCmd.manageAssetAlbums(ctx, a.File, a.ID, a.Albums)
@@ -356,14 +351,18 @@ func (upCmd *UpCmd) handleAsset(ctx context.Context, a *assets.Asset) error {
356351
return err
357352
}
358353

359-
if serverStatus != "duplicate" {
354+
if serverStatus != immich.StatusDuplicate {
360355
// TODO: current version of Immich doesn't allow to add same tag to an asset already tagged.
361356
// there is no mean to go the list of tagged assets for a given tag.
362357
upCmd.manageAssetAlbums(ctx, a.File, a.ID, a.Albums)
363358
upCmd.manageAssetTags(ctx, a)
364359
}
365360
return err
366361

362+
case AlreadyProcessed: // SHA1 already processed
363+
upCmd.app.Jnl().Record(ctx, fileevent.AnalysisLocalDuplicate, a.File, "reason", "the file is already present in the input", "original name", advice.ServerAsset.OriginalFileName)
364+
return nil
365+
367366
case SameOnServer:
368367
a.ID = advice.ServerAsset.ID
369368
a.Albums = append(a.Albums, advice.ServerAsset.Albums...)
@@ -394,7 +393,7 @@ func (upCmd *UpCmd) uploadAsset(ctx context.Context, a *assets.Asset) (string, e
394393
if original != nil {
395394
originalName = original.OriginalFileName
396395
}
397-
if upCmd.assetIndex.uploadedAssets.Contains(ar.ID) {
396+
if a.ID == "" {
398397
upCmd.app.Jnl().Record(ctx, fileevent.AnalysisLocalDuplicate, a.File, "reason", "the file is already present in the input", "original name", originalName)
399398
} else {
400399
upCmd.app.Jnl().Record(ctx, fileevent.UploadServerDuplicate, a.File, "reason", "the server already has this file", "original name", originalName)
@@ -404,6 +403,9 @@ func (upCmd *UpCmd) uploadAsset(ctx context.Context, a *assets.Asset) (string, e
404403
}
405404
a.ID = ar.ID
406405

406+
// // DEBGUG
407+
// if theID, ok := upCmd.assetIndex.byI
408+
407409
if a.FromApplication != nil && ar.Status != immich.StatusDuplicate {
408410
// metadata from application (immich or google photos) are forced.
409411
// if a.Description != "" || (a.Latitude != 0 && a.Longitude != 0) || a.Rating != 0 || !a.CaptureDate.IsZero() {
@@ -437,7 +439,7 @@ func (upCmd *UpCmd) replaceAsset(ctx context.Context, ID string, a, old *assets.
437439
if original != nil {
438440
originalName = original.OriginalFileName
439441
}
440-
if upCmd.assetIndex.uploadedAssets.Contains(ar.ID) {
442+
if a.ID == "" {
441443
upCmd.app.Jnl().Record(ctx, fileevent.AnalysisLocalDuplicate, a.File, "reason", "the file is already present in the input", "original name", originalName)
442444
} else {
443445
upCmd.app.Jnl().Record(ctx, fileevent.UploadServerDuplicate, a.File, "reason", "the server already has this file", "original name", originalName)

0 commit comments

Comments
 (0)