Repository navigation
Conversation
…l books Co-Authored-By: Claude Opus 5.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.
Problem
Deleting a book is very slow on large libraries. On mine (~208k books) every single delete took ~40 s, and since it runs in the web process the whole UI stops responding for that time (healthcheck timeouts,
unhealthy). Resolving 19 duplicate groups took 785 s.delete_whole_book()callsmodify_database_object()for authors, tags, series, languages and publishers, which ends inremove_objects():len(del_element.books)loads every book linked to that element just to see whether the list is empty. Because allBooksrelationships arelazy='selectin', each of those books also pulls its authors, tags, data, comments, identifiers, … For the languagedeuthat is 189,034 books in my library — on every delete.Confirmed with
py-spy dumpduring a duplicate resolution run:The same applies to editing a book's metadata whenever a widely used tag/language/publisher is removed from it, and to deletes from the book page.
Fix
Flush the removed link, then ask the database whether any book still references the element:
with_parentuses the existingbooksbackref, so it works for authors, tags, series, languages, publishers and the multi-value custom column classes alike, without per-type code. The semantics are unchanged: the element is deleted exactly when no book links to it anymore.Testing
On a copy of my
metadata.db(190k books), using the realcps.dbmodels andremove_objects():deufrom a bookdeukeptRunning patched in my instance since; duplicate resolution and manual deletes are now instant and the UI stays responsive.
🤖 Generated with Claude Code