Skip to content

Add Catalog Columns and DB-Backed Live Photo Pairing - #275

Merged
ptr727 merged 12 commits into
developfrom
feature/catalog-columns-live-pairing
Nov 17, 2026
Merged

ptr727 merged 12 commits into
developfrom
feature/catalog-columns-live-pairing

Conversation

@ptr727

@ptr727 ptr727 commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Tracks #274. The files table gains content_identifier, image_hash and metadata_read columns, and process pairs a Live Photo video with its still through the catalog instead of a same-folder name match.

  • Existing databases upgrade in place when a writing command opens them. metadata_read separates "not read yet" from "read, tag absent", so old rows backfill once when the file still exists.
  • IndexTask.IndexFileAsync fills both columns under the existing path, size and mtime cache, using one exiftool run with -ImageDataHash -api ImageHashType=SHA256. index, import and process populate through it. verify indexes without reading metadata, so it needs no exiftool. ExifTool 12.63 or newer is required, per the ExifTool version history, and an older version fails the run with a message.
  • process catalogs every file in parallel first, then runs the per-file pipeline against the warm cache. A new file costs two exiftool runs, one in each phase, because parsed metadata is not carried across phases.
  • With --db, the still is any image row with the same content_identifier, whatever its name or folder, including a still whose file is gone. A row holding the video's own content never counts as its still. Without --db the same-folder lookup is unchanged.
  • A file deleted because its SHA-1 is in the trash database keeps its row, so pairing does not depend on which of the two files process handles first.
  • The image hash is catalog-only. Import dedup stays on whole-file SHA-256.

exiftool cannot create the Apple MakerNotes ContentIdentifier tag in a JPEG that has no maker note (ExifTool FAQ: MakerNotes tags can only be written if they already exist), so no real-still fixture exists. Pairing tests use a video-container file named .heic, and a ProcessCommand test proves the catalog phase runs first.

Verification

  • dotnet build: 0 warnings, 0 errors. dotnet test: 393 total, 388 passed (289 passed and 104 skipped on a runner with no exiftool or ffmpeg, see Run the Media Tests in CI With exiftool and ffmpeg Installed #277), 0 failed, 5 skipped (Docker or Immich unavailable, unchanged).
  • New tests in LivePhotoCatalogTests.cs cover differing stems, different date folders, an id with + and U+FF0F, a still absent from disk, a trashed still processed first, no or non-matching ContentIdentifier, no---db behavior, in-place upgrade, backfill, metadata reading off, and image hash equality. Three tests were shown failing with their guard removed.
  • Local adversarial review passes ran over each stage of the branch. Findings that were fixed are in the commits.

Open review findings

  • Introduced, accepted by the maintainer as a residual risk, stated in ARCHITECTURE.md: a differently encoded video carrying an image extension and a shared ContentIdentifier can pair with another short video. A candidate row never counts as the still when its image_hash or sha256 equals the video's own.
  • Pre-existing, filed: a still cataloged as .heif is renamed to .heic only in the first process round, so a video judged in that round can be kept. See Pair Live Photo Videos With Stills Renamed in the Same Process Round #276.
  • Pre-existing, filed: CI has neither exiftool nor ffmpeg, so the tool-dependent tests skip there. See Run the Media Tests in CI With exiftool and ffmpeg Installed #277.
  • Pre-existing, not filed: a video kept in one run and marked processed is not re-paired in a later run unless --reprocess is given.
  • Pre-existing, not filed: path reuse over a kept row follows the existing size and mtime cache contract.
  • Declined with evidence, no change: two writers upgrading one old database at once can collide on the column add. This is a single-user tool and two writers on one database file is not a supported pattern.
  • Not a defect: the ProcessCommand test fails without the catalog phase in three of three runs, but file enumeration order is not guaranteed, so it can pass without it.

Add content_identifier, image_hash and metadata_read columns to the
files table, upgraded in place on open. The catalog fills them in one
exiftool run that also returns the image data hash, which needs
ExifTool 12.63 or newer.

Make process catalog every file first, then run the per-file pipeline.
With --db a Live Photo video finds its still by ContentIdentifier among
catalogued image rows, whatever the name or folder. Without --db the
same-folder name lookup is unchanged.

Tracks #274.
A video never pairs with a catalog row holding its own content, which a
stale name under an image extension could otherwise produce. A file
that exiftool reports an error for stays unread instead of being stored
as having no tags. A read-only database in the old shape still answers
hash lookups, and the unused partial-schema guard is removed.

Tracks #274.
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Nov 17, 2026
Copilot AI lite review requested due to automatic review settings November 17, 2026 16:21
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active moderate and critical findings remain around stale-row backfilling, nondeterministic Live Photo pair processing, redundant metadata reads, and incomplete phase coverage.

3 open issues
What changed in this PR

This PR adds catalog metadata and database-backed Live Photo pairing across different names and folders, and introduces a two-phase process workflow that catalogs files before processing them.

Changes:

  • Adds content_identifier, image_hash, and metadata_read columns with in-place migration and backfill support.
  • Extends indexing, importing, and processing with ExifTool metadata and image-hash reads.
  • Adds catalog-based pairing, documentation updates, and tests for upgrades, backfill, and pairing behavior.
File Description
README.md Documents catalog columns, ExifTool requirements, and database-backed Live Photo pairing behavior.
PhotoCleanerTests/​LivePhotoCatalogTests.cs Adds tests for catalog pairing, schema upgrades, metadata backfill, image hashes, and related processing behavior.
PhotoCleaner/​ProcessTask.cs Uses database catalog metadata to locate Live Photo stills and exclude self-matches.
PhotoCleaner/​ProcessCommand.cs Adds a cataloging phase before per-file processing.
PhotoCleaner/​MediaUtilities.cs Adds ExifTool version checks and catalog metadata reads including image-data hashes.
PhotoCleaner/​IndexTask.cs Reads and persists catalog metadata during database indexing.
PhotoCleaner/​ImportTask.cs Reads and stores catalog metadata during database-backed imports.
PhotoCleaner/​ExifToolJson.cs Adds JSON deserialization for the image-data hash field.
PhotoCleaner/​DatabaseScope.cs Validates ExifTool image-hash support for writable database commands.
PhotoCleaner/​Database.cs Adds catalog columns, migrations, metadata updates, indexes, and ContentIdentifier lookup queries.
OPERATIONS.md Documents the minimum ExifTool version required for catalog reads.
ARCHITECTURE.md Describes catalog metadata, two-phase processing, and database-based Live Photo pairing.

Review effort: Lite

Comment thread PhotoCleaner/ProcessCommand.cs Resolved
Comment thread PhotoCleaner/ProcessCommand.cs Resolved
Comment thread PhotoCleaner/ProcessCommand.cs Resolved
Deleting a file trashed in Immich no longer deletes its catalog row,
so a Live Photo video pairs with a trashed still whichever of the two
process handles first. Add tests for the trashed-still order and for the
video sorting before its still, and document the cost of the two
exiftool runs per new file.

Tracks #274.
Verify indexes without reading catalog metadata, so it needs no
exiftool and no longer hashes image data for every already verified
file. Reuse the pre-process SHA-256 for the Live pairing exclusion,
drop the unused row delete, and correct the documentation of the
upgrade and rehash behavior.

Tracks #274.
The test starts with both files unindexed and the video listed before
its still. It fails when the catalog phase is removed.

Tracks #274.
Import skips a known source before reading metadata, so only index and
process backfill an old row.

Tracks #274.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical P1 issues remain: stale image-extension rows can cause videos without stills to be deleted, and the required Keys:ContentIdentifier mapping is missing, preventing valid live-photo video pairing.

2 open issues
3 resolved since last review

Review effort: Lite

Comment thread PhotoCleaner/Database.cs Resolved
Comment thread PhotoCleaner/ExifToolJson.cs Resolved
The IndexTask cache tests index dummy text files and need no metadata,
so they read none. They pass on a runner with no exiftool installed.

Tracks #274.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.03226% with 242 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.25%. Comparing base (a3158ce) to head (0bb795d).
⚠️ Report is 112 commits behind head on develop.

Files with missing lines Patch % Lines
PhotoCleaner/Database.cs 56.12% 63 Missing and 5 partials ⚠️
PhotoCleaner/ProcessTask.cs 0.00% 53 Missing ⚠️
PhotoCleaner/MediaUtilities.cs 2.22% 44 Missing ⚠️
PhotoCleaner/IndexTask.cs 26.31% 26 Missing and 2 partials ⚠️
PhotoCleaner/ProcessCommand.cs 0.00% 28 Missing ⚠️
PhotoCleaner/ImportTask.cs 0.00% 15 Missing ⚠️
PhotoCleaner/DatabaseScope.cs 0.00% 5 Missing ⚠️
PhotoCleaner/VerifyCommand.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #275      +/-   ##
===========================================
- Coverage    43.37%   41.25%   -2.13%     
===========================================
  Files           28       27       -1     
  Lines         3896     4138     +242     
  Branches       306      362      +56     
===========================================
+ Hits          1690     1707      +17     
- Misses        2154     2361     +207     
- Partials        52       70      +18     
Flag Coverage Δ
dotnet 41.25% <29.03%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Maintainer judgment is required because the catalog lacks durable media identity, allowing stale or misnamed video rows to be mistaken for stills and potentially deleted destructively.

1 open issue
1 resolved since last review

Review effort: Lite

Move the schema and mapping tests to a class with no tool dependency so
they run on a runner without exiftool. The media fixture skips instead
of failing when the installed exiftool is older than the minimum.

Tracks #274.
The media fixture stays unchanged, so a host with an exiftool older than
the minimum fails with the version message instead of skipping tests
that never read catalog metadata.

Tracks #274.
@ptr727

ptr727 commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 5967599c9b70ee306dfbbdc2531c625d7303cb1d, the content this pull request carries at that commit against develop, and it recorded 1 finding.

A catalog row whose image hash equals the video's own never counts as
its still, so a copy of one video under an image extension no longer
deletes the video. Test stills use a different video as their media.
List the new test files in the architecture notes.

Tracks #274.
The stale row has no image hash, so only the SHA-256 exclusion can keep
the video from pairing with itself. Correct the stale fixture comment.

Tracks #274.
@ptr727

ptr727 commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 0bb795d0ec47d2bc38a75c7e0a6d5a1e74d7d6a7, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 826f0c0 into develop Nov 17, 2026
23 checks passed
@ptr727
ptr727 deleted the feature/catalog-columns-live-pairing branch November 17, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants