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
|
|
@ -295,6 +295,26 @@ async def test_doc_modeler_calibre_cover(test_session, async_client, test_direct
|
|||
assert test_session.query(FileGroup).count() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_doc_modeler_calibre_hides_files_in_the_modelers_session(test_session, async_client, test_directory,
|
||||
example_epub, example_mobi, image_file,
|
||||
refresh_files):
|
||||
"""Hiding a Calibre book's cover and metadata FileGroups uses the modeler's own session. A second session
|
||||
cannot take SQLite's write lock while the modeler holds the item's transaction: it waited out the busy timeout
|
||||
and failed, leaving the rows and the ebook unmodeled."""
|
||||
(test_directory / 'metadata.opf').touch()
|
||||
shutil.move(image_file, test_directory / 'cover.jpg')
|
||||
|
||||
# `create=True`: the fixed module no longer imports it; the patch still catches any reintroduced use.
|
||||
with patch('modules.docs.models.get_db_session', create=True,
|
||||
side_effect=AssertionError('opened a second session')):
|
||||
await refresh_files()
|
||||
|
||||
doc: Doc = test_session.query(Doc).one()
|
||||
assert doc.cover_path
|
||||
assert test_session.query(FileGroup).count() == 1, 'The cover and metadata FileGroups were deleted'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_doc_modeler_normalizes_author(async_client, test_session, test_directory, example_epub, refresh_files):
|
||||
"""Author names are normalized before creating collections (e.g. quotes stripped)."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue