mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Hiding a Calibre book's cover and metadata uses the modeler's session (#936)
Doc._hide_calibre_files opened a second write session while the modeler held the item's transaction. SQLite has one writer, so the second session waited out the 30 s busy timeout and failed with "database is locked"; the modeler retried three times, so every Calibre epub cost about 98 s and stayed unmodeled, and the cover.jpg / metadata.opf FileGroups it should have deleted survived. On a library of 1663 Calibre books the global refresh's modeling phase would have taken about two days. The nested session dates from before the SQLite cutover, when Postgres row locks let it work. The delete now runs in the caller's session. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
e6b7b9e5dd
commit
c0452e29e6
3 changed files with 35 additions and 13 deletions
|
|
@ -110,7 +110,7 @@ def _model_doc(file_group: FileGroup, session: Session) -> Doc:
|
|||
doc.size = file_group.primary_path.stat().st_size if file_group.primary_path.exists() else None
|
||||
|
||||
# Handle cover.
|
||||
_handle_doc_cover(doc, file_group, metadata)
|
||||
_handle_doc_cover(session, doc, file_group, metadata)
|
||||
|
||||
# Store data dict.
|
||||
data = file_group.data or {}
|
||||
|
|
@ -154,14 +154,14 @@ def _replace_doc_sections(session: Session, doc: Doc, sections):
|
|||
])
|
||||
|
||||
|
||||
def _handle_doc_cover(doc: Doc, file_group: FileGroup, metadata):
|
||||
def _handle_doc_cover(session: Session, doc: Doc, file_group: FileGroup, metadata):
|
||||
"""Handle cover extraction and storage for a doc."""
|
||||
|
||||
# Check for Calibre cover first (epub only) — must happen before poster check
|
||||
# since Calibre cover has a different stem ("cover.jpg" not matching epub stem).
|
||||
if file_group.mimetype and file_group.mimetype.startswith('application/epub'):
|
||||
if calibre_cover := discover_calibre_cover(file_group.primary_path):
|
||||
doc._hide_calibre_files(file_group)
|
||||
doc._hide_calibre_files(session, file_group)
|
||||
file_group.append_files(calibre_cover)
|
||||
file_group.data = file_group.data or {}
|
||||
file_group.data['cover_path'] = calibre_cover.name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue