Skip to content

Use the Image-Data Hash for Duplicate Detection and the Immich Trash Match #278

Closed

Description

@ptr727

Summary

Use the image-data hash, which the catalog now records per file (#274), so that duplicate detection and the Immich trash match survive a change that touches only metadata.

Problem

Import dedup and the trash match both compare whole-file hashes (SHA-256 for dedup, SHA-1 for trash). Two copies of one photo that differ only in metadata bytes therefore look like two different files:

  • A downloader that rewrites metadata, or a switch to a different downloader, makes every previously imported file look new, so it is imported again and becomes a duplicate in Immich.
  • An asset the owner removed in Immich is recorded in the trash database by the SHA-1 of the exact bytes Immich held. The same photo arriving again with different metadata bytes does not match, so the removed photo comes back.

Example with constructed names: IMG_1234.HEIC is imported and uploaded, then trashed in Immich. Later the source delivers IMG_1234.HEIC again with an extra XMP block. Its SHA-256 and SHA-1 differ, its image-data hash is identical, and today it is imported and uploaded a second time.

Proposal

  1. Dedup: an opt-in import option that also skips a source file whose image-data hash is already known to the import database, and logs which known file it matched.
  2. Trash: when an asset is recorded as trashed, also record the image-data hash of the processed file that was uploaded (looked up by its SHA-1 in the process database), and let import and process treat a file with a recorded image-data hash as trashed.
  3. Keep the whole-file hash behaviour as the default until the option has been validated, since an image-data match is deliberately weaker than a byte match: two files with equal image data and different metadata are treated as one.

Notes

  • The image-data hash is absent for formats ExifTool cannot hash; those keep today's whole-file behaviour.
  • A re-encoded or edited rendition has different image data and is unaffected.
  • The trash database schema gains a column, so it needs the same in-place upgrade the files table received in Add Catalog Columns and DB-Backed Live Photo Pairing #274.

Activity

  1. added
    enhancement
    on Nov 17, 2026
  2. ptr727 commented on Nov 18, 2026

    @ptr727
    OwnerAuthor

    Released (2026-11-18): #288 merged to develop at 3731ff9, and its branch and worktree are cleaned up. The issue closes when the promotion to main lands.

    Backlog burndown claim (2026-11-18, round 1 refill): group #278 on branch feature/image-hash-dedup-trash.

    Predicted files:

    • PhotoCleaner/CommandLine.cs, PhotoCleaner/ImportTask.cs, PhotoCleaner/ImportCommand.cs, PhotoCleaner/Database.cs
    • PhotoCleaner/TrashDatabase.cs, PhotoCleaner/TrashCommand.cs, PhotoCleaner/ProcessTask.cs, PhotoCleaner/ProcessCommand.cs
    • PhotoCleanerTests/ImportTaskTests.cs, PhotoCleanerTests/TrashDatabaseTests.cs, PhotoCleanerTests/TrashCommandTests.cs, PhotoCleanerTests/ProcessTaskTests.cs, PhotoCleanerTests/CommandLineTests.cs, PhotoCleanerTests/DatabaseTests.cs
    • README.md, ARCHITECTURE.md, GUIDE.md, OPERATIONS.md
    • cspell.json (granted 2026-11-18: the new option names imagehash and processdb need the spell-check word list)
  3. ptr727 commented on Nov 18, 2026

    @ptr727
    OwnerAuthor

    Maintainer's answer (2026-11-18, backlog burndown): merge #288 as is. After a duplicate cull, the trashed copy's image hash also matches the kept copy. process --imagehash then deletes the kept copy's processed file, and import --imagehash skips its source. That is the trade-off this issue accepted (equal image data counts as one file). It is opt-in and documented, so no safeguard is required first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions