feat: batch image deletion with a single embeddings-index rewrite#351
Merged
Conversation
Deleting N starred images from the favorites menu previously issued N
serial delete_image requests, each of which loaded and atomically
rewrote the entire .npz index — O(N x index size) I/O that made
multi-select deletes crawl on large albums.
- New POST /delete_images/{album_key} endpoint deletes the files (or
routes each through InvokeAI for board albums), reports per-item
errors, and drops all rows in one rewrite.
- Embeddings.remove_images_from_embeddings() maps all sorted-order
indices against one snapshot of the (modtime, filename) lexsort, so
callers need no reverse-order shifting; the singular method now
delegates to it. The rewrite carries over non-per-image keys
(model_id etc.) so the encoder stamp survives.
- deleteBookmarkedImages() now sends one request and dispatches the
albumChanged deletion event with the indices actually removed.
Co-Authored-By: Claude Fable 5 <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
Deleting N starred images from the favorites menu previously issued N serial
DELETE /delete_imagerequests, and each one loaded and atomically rewrote the entire.npzindex — O(N × index size) I/O that made multi-select deletes crawl on large albums. Deleting 20 favorites from a 50k-image album meant reading and rewriting the full index 20 times.This adds a batch path that does the whole selection with one request and one index rewrite, so a multi-select delete now costs the same index I/O as deleting a single image.
Changes
Backend
POST /delete_images/{album_key}endpoint takes{indices, move_to_trash}, resolves every index against one snapshot of the sort order, deletes the files, and drops all their rows in a single rewrite. Per-item failures (out-of-range index, missing file, access denied) are reported in anerrorslist without failing the batch.Embeddings.remove_images_from_embeddings(indices)maps all sorted-order indices through the(modtime, filename)lexsort against one snapshot — callers need no reverse-order shifting — and its singleatomic_savezcarries over the non-per-image keys (model_idetc., per fix: deleting an image no longer breaks search or drops out of search mode #350) so the encoder stamp survives. The singularremove_image_from_embeddingsnow delegates to it.Frontend
deleteImages()helper inindex.js.deleteBookmarkedImages()inbookmarks.jssends one batch request instead of a serial per-image loop, and dispatches the existingalbumChangeddeletion event with the indices the server actually removed.Testing
deleteImages()request shape and error propagation.🤖 Generated with Claude Code