fix(gallery): traverse image subfolders when finding orphaned db entries#9291
Open
lstein wants to merge 1 commit into
Open
fix(gallery): traverse image subfolders when finding orphaned db entries#9291lstein wants to merge 1 commit into
lstein wants to merge 1 commit into
Conversation
When invokeai.yaml sets an image_subfolder_strategy, new images are written into subfolders of outputs/images (by date, type, or hash). The orphaned-db- entry cleanup only checked the top-level outputs/images directory, so every image stored in a subfolder looked missing and its (valid) database row was deleted. Add PhysicalFileMapper.get_all_image_filenames_recursive(), which globs the entire outputs/images tree, and use it for the orphan check. Image names are globally unique UUIDs, so a basename set is collision-free; thumbnails (.webp) and the sibling images-archive directory are naturally excluded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes data loss in
scripts/gallery_maintenance.py(logic ininvokeai/backend/util/gallery_maintenance.py) when animage_subfolder_strategyis configured.When
invokeai.yamlsets animage_subfolder_strategy(date,type, orhash), new images are written into subfolders ofoutputs/images(e.g.outputs/images/2026/03/17/<name>.png). The Clean Orphaned Database Entries operation only checked the top-leveloutputs/imagesdirectory for each image, so every image living in a subfolder appeared to be missing — and its perfectly valid database row was deleted. Users reported thousands of entries being wrongly removed.Fix
PhysicalFileMapper.get_all_image_filenames_recursive(), which globs the entireoutputs/imagestree (**/*.png) and returns the set of all image basenames found anywhere.clean_orphaned_db_entries: a DB row is now only considered orphaned if its file is absent from the whole tree, not just the top level.Why this is safe:
.webpand are excluded by the.pngglob.images-archivedirectory is a sibling ofimages/, so it is not traversed.os.path.existsstat calls.Scope is intentionally limited to the orphaned-DB-entry operation, which is the one that destructively deletes database rows. The archive/thumbnail operations only move or create files and were left unchanged to avoid surprising side effects.
Testing
python3 -m py_compilepasses..webpthumbnails and the siblingimages-archivedirectory are correctly excluded.🤖 Generated with Claude Code