Skip to content

fix(stats): match a book once when several of its hashes share a fingerprint - #60

Merged
audemed44 merged 1 commit into
mainfrom
fix/stats-import-duplicate-hashes
Oct 24, 2026
Merged

audemed44 merged 1 commit into
mainfrom
fix/stats-import-duplicate-hashes

Conversation

@audemed44

Copy link
Copy Markdown
Owner

Why

Since #58 was deployed, every library scan has logged stats DB import failed: Multiple rows were found when one or none was required. No KOReader reading sessions have been imported since. They're still in KOReader's statistics database, so nothing is lost.

When Shelfloom writes metadata into an EPUB, the file's SHA changes. KOReader's partial MD5 often doesn't, because it samples only a few chunks of the file. 22 live books now have two book_hashes rows with the same KOReader fingerprint. Lookups that joined book_hashes returned those books twice, and oneBook treated that as ambiguous.

What

The three lookups that joined book_hashes (stats match, .sdr match, findByHash) now match on the book: books.id IN (SELECT book_id FROM book_hashes WHERE …). Each book counts once. Two different books with the same fingerprint are still reported as ambiguous.

Testing

  • New TestStatsMatchSharedFingerprint fails without the fix and passes with it. Full go vet and go test -race pass.
  • Ran the real stats import against copies of the live Shelfloom database and KOReader statistics.sqlite3. Without the fix it fails with the same error; with the fix it succeeds.

…erprint

Writing library metadata into EPUBs changes a file's SHA but often not
KOReader's partial MD5, which samples only a few chunks. A book then has
two book_hashes rows with the same fingerprint, and the lookups that
joined book_hashes returned it twice: the KOReader statistics import
failed with "Multiple rows were found" and imported no sessions.

Match on the book (books.id IN the hashes' book_ids) so each book counts
once; two different books sharing a fingerprint are still ambiguous.
@audemed44
audemed44 merged commit 82db3c9 into main Oct 24, 2026
2 checks passed
@audemed44
audemed44 deleted the fix/stats-import-duplicate-hashes branch October 24, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant