PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

Feat: Implement Incremental Indexing Engine for Scalable Library Management

Open Devnil434 opened this issue 9 months ago โ€ข 6 comments

๐Ÿš€ Problem

Currently, library rescans may reprocess many or all images, even if they haven't changed.
For large libraries (10k+ images), this leads to:

  • Slow refresh times
  • Unnecessary ML reprocessing
  • High CPU usage
  • Poor scalability

There is no reliable mechanism to detect:

  • Newly added files
  • Modified files
  • Deleted files
  • Unchanged files

๐Ÿ’ก Proposed Solution

Implement a true Incremental Indexing Engine that:

  • Stores file metadata (e.g., path, size, last modified time, optional hash)
  • Processes only new or modified files
  • Skips unchanged files
  • Removes deleted files from the database
  • Cleans associated embeddings and thumbnails

๐ŸŽฏ Expected Benefits

  • Significant performance improvement for large libraries
  • Reduced redundant ML inference
  • Better database consistency
  • Production-grade scalability

๐Ÿ› ๏ธ Implementation Overview

  1. Extend image table schema to store file metadata
  2. Add comparison logic during rescans
  3. Update indexing pipeline to process only changed files
  4. Handle cleanup for deleted files

๐Ÿงช Acceptance Criteria

  • Only new/modified files are processed during rescan
  • Deleted files are removed from DB
  • No redundant ML processing occurs
  • Works reliably on large datasets (10k+ images)

๐Ÿ™‹ I would like to work on this issue.

Devnil434 avatar Feb 20 '26 09:02 Devnil434

๐Ÿ‘‹ Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)

github-actions[bot] avatar Feb 20 '26 09:02 github-actions[bot]

Hi @rahulharpal1603

Iโ€™ve gone through the issue and the current indexing flow, and Iโ€™d like to confirm my understanding before starting implementation.

From what I see, the current rescan mechanism does not differentiate between:

new files

modified files

deleted files

unchanged files

which results in redundant ML embedding generation and full-library reprocessing.

Iโ€™m proposing the following structured approach:

1๏ธโƒฃ Schema Extension (Backward Compatible)

Extend the image table to store:

file_path

file_size

last_modified_timestamp

optional hash (only if metadata comparison is insufficient)

2๏ธโƒฃ Incremental Comparison Logic During Rescan

If file not in DB โ†’ process & insert

If metadata unchanged โ†’ skip

If metadata changed โ†’ reprocess & update embeddings

If DB entry missing on disk โ†’ delete record + clean embeddings & thumbnails

3๏ธโƒฃ Cleanup & Consistency

Ensure associated embeddings are safely removed for deleted/modified files

Avoid redundant ML inference

4๏ธโƒฃ Testing Strategy

Validate behavior on:

newly added files

modified files

deleted files

large dataset simulation (10k+ entries)

Before I begin implementation, Iโ€™d like to confirm:

Whether metadata-based detection is sufficient or if you prefer hash-based validation

If there are any architectural constraints I should follow for the indexing pipeline

Iโ€™d be happy to take this up and submit a draft PR once the approach is aligned.

Looking forward to your feedback ๐Ÿ™‚

codewith-shivansh avatar Mar 01 '26 09:03 codewith-shivansh

@rahulharpal1603 Sir can you please assign this issue to me ?

JIturiDashami avatar Jul 31 '26 15:07 JIturiDashami

Hi @rahulharpal1603 , following up โ€” is this issue still open for assignment? Happy to work on this issue, can you please assign it to me?

JIturiDashami avatar Aug 14 '26 18:08 JIturiDashami

@rahulharpal1603 @rohan-pandeyy following up on this.

Checked the recent commits before writing this โ€” PR #1481 (merged Aug 10) already does the "skip unchanged files" part. It stores file_mtime with file_size and skips a file if size, mtime, and thumbnail all match. Half of this issue is already done; it just wasn't linked here.

What's not done yet: deleted files. If a file is removed from disk, nothing cleans up its DB row, embeddings, or thumbnail. Over time, that leaves stale data in the library.

I want to take this scoped to just that:

Detect DB entries whose file no longer exists on disk during rescan Delete the row and clean up embeddings/tags/thumbnail tied to it Tests for deletion + regression tests for the unchanged/modified cases Can you assign this to me? Let me know if you want it scoped differently.

bhavyamsharmaa avatar Aug 21 '26 07:08 bhavyamsharmaa

Hi @Devnil434 / maintainers,

Iโ€™d like to contribute to #1186 if collaboration is possible.

I inspected the current image indexing flow and found that PictoPy already has part of the incremental mechanism: image metadata stores file size/mtime, unchanged files can be skipped, and existing image IDs are preserved through the path conflict update.

The remaining consistency gap Iโ€™d like to address is modified-file invalidation. A modified image can currently retain its previous isTagged / isEmbedded state and derived data such as image classes, face embeddings, and semantic embeddings.

My proposed scope is:

  • Explicitly distinguish new / unchanged / modified / deleted files during image indexing.
  • Preserve the existing image.id for modified files.
  • Refresh thumbnail + metadata only for new/modified files.
  • Invalidate stale derived ML/index data for modified images.
  • Remove deleted files and associated derived data safely.
  • Ensure unchanged images do not trigger thumbnail generation or ML inference.
  • Add backend tests covering new, unchanged, modified, deleted, and mixed-rescan scenarios.
  • Keep the implementation within the existing route โ†’ utils โ†’ database architecture rather than introducing a separate indexing subsystem.

Iโ€™d be happy to work on this as a contribution while coordinating with whoever is currently working on the issue.

Would this scope be useful, or would you prefer me to take a specific sub-part of #1186?

Sam240107 avatar Oct 03 '26 03:10 Sam240107