[BUG] Author refresh inserts every ebook book and edition twice after adding an author via author search

Aperta
#323 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, docker, sqlite
Ambito
backend, database

Direzione di ricerca

Start with AuthorLibraryService.ProcessBooksForAuthor, RefreshAuthorService.GetRemoteChildren, and NzbDrone.Core.Books.EditionRepository, using the quoted duplicate editions as the reproduction. Trace how each refresh path snapshots local books and inserts missing books or editions, then verify the reported uniqueness tuple at the database boundary. Done means one refresh preserves 301 audiobook and 248 ebook rows without duplicate ebook editions, and an appropriate test reproduces the two-pass refresh.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

After adding an author via author search, the first author refresh that pulls in the Ebook side inserts every ebook book row (and its editions) twice. The two rows are identical apart from their local IDs: same title, foreignBookId, baseBookId and foreignEditionId, both created in the same second. The author page then lists every ebook twice.

The refresh itself logs each book as created only once (MISSING_BOOK_CREATED), so the duplication happens below that decision, at insert time.

To Reproduce

Observed once, on an author added via author search (R.A. Salvatore, hc:1210161). Other authors in the same library were added via book search and are not affected.

  1. Search for the author and add them. At add time the author had no Ebook metadata profile yet. The add logged:

    16:35:47.3|Info|AuthorLibraryService|[METADATA-PROFILE] No Ebook metadata profile configured for author 'R.A. Salvatore'. Treating Ebooks as disabled and excluding 542 remote books; unprotected local Ebooks will be pruned on refresh.
    16:35:47.4|Info|AuthorLibraryService|ProcessBooksForAuthor: Returning 301 books (from 1084 total, 1084 de-duped, 301 profile-filtered, 0 excluded, retained editions applied)
    

    → 301 audiobook rows created (IDs 5244–5544). Correct so far.

  2. ~18 s later a RefreshAuthor is queued (authorId: 29, isNewAuthor: false, forceRefresh: true, refreshMetadata: true, trigger: unspecified). The author now has an Ebook metadata profile (ebookMetadataProfileId: 2, "Ebook Default").

  3. During that refresh:

    16:36:07.3|Info|AuthorLibraryService|ProcessBooksForAuthor: Returning 248 books (from 542 total, 542 de-duped, 301 profile-filtered, 53 excluded, retained editions applied)
    16:36:07.8|Info|RefreshAuthorService|GetRemoteChildren: Returning 549 books (from 1084 total, 1084 de-duped, 602 profile-filtered, 53 excluded, retained editions applied)
    16:36:07.9|Info|RefreshAuthorService|MISSING_BOOK_CREATED: 'Homeland' - Original narrator 'NULL' -> NULL (preventing metadata pollution)
    ... (248 MISSING_BOOK_CREATED lines in total, one per book)
    16:36:13.0|Warn|NzbDrone.Core.Books.EditionRepository|Found 2 editions with ForeignEditionId gr:212009349-ebook; legacy singular lookup using oldest (Id=22065)
    16:36:13.0|Warn|NzbDrone.Core.Books.EditionRepository|Found 2 editions with ForeignEditionId hc:edition:32870113-ebook; legacy singular lookup using oldest (Id=22066)
    ...
    
  4. Result: 496 ebook rows for 248 ebook books — two contiguous blocks, IDs 5545–5792 and 5793–6040, every row with added: 2026-10-17T20:36:07Z. Example for one book:

    id mediaType foreignBookId foreignEditionId
    5254 audiobook hc:28782 gr:18339544-audiobook
    5555 ebook hc:28782 gr:222835996-ebook
    5803 ebook hc:28782 gr:222835996-ebook

    Grouping GET /api/v1/book?authorId=29 by (mediaType, foreignEditionId) gave 248 groups of exactly 2 for ebooks and 0 duplicates for audiobooks.

Expected behavior

Each ebook book/edition is inserted once. The refresh should not create a row whose (authorId, mediaType, foreignEditionId) already exists, and ideally the DB would enforce that uniqueness.

System Information:

  • OS: Linux host, official Docker image (container reports Ubuntu)
  • Chaptarr Version: 0.9.965.0 (develop branch per /api/v1/system/status)
  • Installation Method: Docker (Docker Compose)
  • Database: SQLite

Additional context

  • None of the duplicated rows were monitored or had files, so cleanup was safe: deleting the second copy of each pair (DELETE /api/v1/book/{id}?deleteFiles=false&addImportListExclusion=false for IDs 5793–6040) removed the duplicate editions too. Afterwards 549 rows remain (301 audiobook + 248 ebook) with no duplicates.
  • The two library passes in step 3 (AuthorLibraryService.ProcessBooksForAuthor returning the 248 ebooks, and RefreshAuthorService.GetRemoteChildren returning all 549) both run in the same refresh, a few hundred ms apart. A guess, not verified against the code: both paths add the 248 missing ebooks, each against a snapshot of local books taken before the other's insert.
  • I'm not sure which UI action queued the RefreshAuthor in step 2 (trigger: unspecified). Most likely it was enabling the Ebook side/profile on the newly added author.
  • Related but different: #111 and #285 involve duplicates with different work/edition IDs, or clones made by import. Here the rows are exact copies created by a single refresh. #223 describes a similar find-then-insert race, but in the HTTP response cache.

Logs

The relevant lines from /config/logs/chaptarr.txt are quoted above (timestamps in America/Toronto, UTC−4). Full logs available on request.


This report was prepared with AI assistance (Claude Code) from the reporter's API data and logs.

Lingua principale
C#
Stelle
664
Fork
48
Merge medio
5h 24m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Chaptarr/chaptarr

Tutte le issue di Chaptarr/chaptarr

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.