Skip to content

Fix #542: audiobook total size = sum of per-file sizes#738

Open
Paelsmoessan wants to merge 1 commit into
Listenarrs:canaryfrom
Paelsmoessan:fix/542-size-upstream
Open

Fix #542: audiobook total size = sum of per-file sizes#738
Paelsmoessan wants to merge 1 commit into
Listenarrs:canaryfrom
Paelsmoessan:fix/542-size-upstream

Conversation

@Paelsmoessan

Copy link
Copy Markdown

Problem

An audiobook's total size (Audiobook.FileSize) is wrong. For multi-file audiobooks it shows only one file's size (a 15-part, ~70 MB book displays ~4.7 MB), and for books that were never organized it shows nothing at all.

Root cause

FileSize is a stored scalar that is only ever set to the primary (alphabetically-first) file's size during rename (UpdateAudiobookPathSummary), or left null. It is never the sum of the audiobook's files. The per-file sizes (AudiobookFile.Size, from the filesystem) are already correct; only the aggregate is wrong.

Fix

Derive the total from the already-correct per-file sizes at read time, instead of relying on the stale scalar:

  • New IAudiobookFileRepository.GetTotalSizesByAudiobookIdAsync (SUM grouped by audiobook), mirroring GetCountsByAudiobookIdAsync, for the list view (its format summaries carry no size).
  • AudiobookDtoFactory and LibraryQueryWorkflow.MapDetails sum the loaded Files.

Nothing sorts/filters by FileSize in SQL, so in-memory/aggregate derivation is safe. No migration and no re-scan needed (per-file sizes are already stored).

Tests

Adds a multi-file sum test to AudiobookDtoFactoryTests (three files summed, not the primary file nor the stale scalar). Verified live: a 15-part book that showed ~4.7 MB now shows its correct ~70 MB total, and a previously blank book now shows its size.

Closes #542.

🤖 Generated with Claude Code

…ti-file aware)

Audiobook.FileSize was only ever set to the primary (alphabetically-first) file's
size during rename, or left null, never the sum. Multi-file audiobooks showed a
too-small size, and un-organized ones showed none (detail view hides null).

Derive the total from the already-correct per-file sizes at read time instead of
relying on the stale scalar:
- New IAudiobookFileRepository.GetTotalSizesByAudiobookIdAsync (SUM grouped by
  audiobook), mirroring GetCountsByAudiobookIdAsync, for the list view (its format
  summaries carry no Size).
- AudiobookDtoFactory and LibraryQueryWorkflow.MapDetails sum the loaded Files.
Nothing sorts/filters by FileSize in SQL, so in-memory/aggregate derivation is safe.

Adds a multi-file sum test to AudiobookDtoFactoryTests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Paelsmoessan Paelsmoessan requested a review from a team July 5, 2026 20:07
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.

Incorrect size for audiobook given

1 participant