Skip to content

fix(audiobooks): improve poster enrichment throughput - #94

Merged
Quick104 merged 4 commits into
mainfrom
work/audiobook-fixes-main
Jun 8, 2026
Merged

Quick104 merged 4 commits into
mainfrom
work/audiobook-fixes-main

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • increase audiobook poster enrichment throughput and make the worker count respect the active batch size
  • route audiobook ScanSubtree and ScanFile calls through the audiobook scanner instead of the generic video path
  • normalize audiobook poster URLs through the poster image resolver, including related rails
  • enable the Audiobookshelf-compatible listener by default, repair databases that inherited the stale disabled value, and remove the obsolete audiobooks.enabled setting

Verification

  • go test ./internal/config ./internal/scanner ./internal/catalog ./internal/audiobooks/...

Notes

The ABS compatibility setting now defaults to true, matching Docker deployments that publish :13378. Operators can still turn it off from Admin Settings -> Compatibility Proxies -> Audiobookshelf.

Summary by CodeRabbit

  • New Features

    • Audiobook enrichment batch size and worker concurrency are now configurable via environment variables for performance tuning.
    • Audiobookshelf compatibility listener is enabled by default.
  • Bug Fixes

    • Audiobook cover images now correctly resolve using poster variants.
  • Tests

    • Added comprehensive test coverage for audiobook enrichment configuration, cover resolution, and library scanning.

@RXWatcher

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@RXWatcher, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 24 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c8f0272-4b14-46e1-be00-c3d0a1f0a3e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8291be1 and a0514e3.

📒 Files selected for processing (3)
  • internal/audiobooks/enrichment_test.go
  • internal/scanner/audiobook_test.go
  • internal/scanner/scanner.go
📝 Walkthrough

Walkthrough

This pull request introduces four coordinated audiobook enhancements: configurable enrichment sweep sizing via environment variables, unified audiobook poster URL presigning across catalog and GraphQL services, audiobook-specific library scanning routes, and default enablement of the Audiobookshelf compatibility listener via database configuration and SQL migrations.

Changes

Audiobook Features and Configuration

Layer / File(s) Summary
Audiobook enrichment batch size and worker configuration
internal/audiobooks/enrichment.go, internal/audiobooks/enrichment_test.go
Audiobook enrichment sweeps now use SILO_AUDIOBOOK_ENRICH_BATCH_SIZE (default 250) and SILO_AUDIOBOOK_ENRICH_WORKERS (default 4), with workers capped to the batch size. NewEnricher initializes from these environment-driven helpers instead of fixed defaults. Three new tests verify configuration application, worker capping behavior, and fallback handling for invalid values.
Unified audiobook poster URL presigning
internal/audiobooks/service.go, internal/audiobooks/service_test.go, internal/catalog/detail.go, internal/catalog/detail_audiobook_test.go
A new presignAudiobookPosterURL helper centralizes audiobook poster URL presigning via PresignImageURL(..., "poster", variant) and is applied in three catalog query paths (also-by-author, similar-by-genres, series). ABS handler cover resolution also switches to the image-type-aware presign method. Tests verify poster variant handling and URL generation in both catalog and GraphQL contexts.
Audiobook-specific library scanning pipeline
internal/scanner/scanner.go, internal/scanner/audiobook_test.go
ScanSubtree and ScanFile now detect audiobook-type libraries and route them through the ScanAudiobookFolder pipeline instead of video/movie scanning. A scoped folder-paths helper restricts ScanSubtree to the requested directory, and ScanFile validates audio extensions before routing. Two integration tests confirm the audiobook pipeline is used and generic movie scanning logic is bypassed.
Enable Audiobookshelf compatibility by default
internal/config/db_loader.go, internal/config/db_loader_test.go, migrations/sql/20260607161414_add_audiobookshelf_compat_enabled.sql, migrations/sql/20260608183000_enable_audiobookshelf_compat_default.sql
LoadFromDB now defaults audiobookshelf_compat.enabled to true, enabling the Audiobookshelf listener on :13378 by default. Two SQL migrations ensure the setting is applied: the first sets the initial value to true, and the second normalizes any empty/false values and removes the legacy audiobooks.enabled kill-switch. The config test is updated to verify the new default behavior.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(audiobooks): improve poster enrichment throughput' directly aligns with the main objective: increasing audiobook poster enrichment throughput by configuring batch size and worker count via environment variables.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch work/audiobook-fixes-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/audiobooks/enrichment_test.go (1)

66-94: 💤 Low value

Consider adding a test case for worker capping in NewEnricher context.

The existing tests provide good coverage, but there's a small gap: no test demonstrates that NewEnricher actually caps workers when SILO_AUDIOBOOK_ENRICH_WORKERS exceeds SILO_AUDIOBOOK_ENRICH_BATCH_SIZE. For example:

func TestNewEnricherCapsWorkersToConfiguredBatchSize(t *testing.T) {
	t.Setenv("SILO_AUDIOBOOK_ENRICH_BATCH_SIZE", "50")
	t.Setenv("SILO_AUDIOBOOK_ENRICH_WORKERS", "100")

	e := NewEnricher(nil, nil, nil, nil, nil, nil)

	if e.workers != 50 {
		t.Fatalf("workers = %d, want 50 (capped to batchSize)", e.workers)
	}
}

This would verify the integration of both helpers in NewEnricher when capping applies.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/audiobooks/enrichment_test.go` around lines 66 - 94, Add a new unit
test that verifies NewEnricher caps the workers to the configured batch size:
set environment variables "SILO_AUDIOBOOK_ENRICH_BATCH_SIZE" to a smaller value
(e.g., "50") and "SILO_AUDIOBOOK_ENRICH_WORKERS" to a larger value (e.g.,
"100"), call NewEnricher(nil, nil, nil, nil, nil, nil), and assert that the
returned enricher's e.workers equals the batch size (e.batchSize) rather than
the larger env value; this ensures NewEnricher correctly integrates
audiobookEnrichBatchSize/audiobookEnrichWorkers capping logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/scanner/scanner.go`:
- Around line 250-255: The code currently passes filepath.Clean(subtreePath)
(cleanSubtree) directly into ScanAudiobookFolder which can be "." for empty or
relative inputs and thus expand scope incorrectly; add a guard in the
ScanAudiobookFolder call sites (e.g., where cleanSubtree is computed and passed
to ScanAudiobookFolder and the analogous use around ScanAudiobookFolder at the
later location) that validates cleanSubtree is non-empty, not ".", and is an
absolute or appropriately rooted path (or otherwise reject leading ".."),
returning an error instead of calling ScanAudiobookFolder when the scope root is
invalid; keep the validation next to the cleanSubtree computation and reuse the
same check for both occurrences.

---

Nitpick comments:
In `@internal/audiobooks/enrichment_test.go`:
- Around line 66-94: Add a new unit test that verifies NewEnricher caps the
workers to the configured batch size: set environment variables
"SILO_AUDIOBOOK_ENRICH_BATCH_SIZE" to a smaller value (e.g., "50") and
"SILO_AUDIOBOOK_ENRICH_WORKERS" to a larger value (e.g., "100"), call
NewEnricher(nil, nil, nil, nil, nil, nil), and assert that the returned
enricher's e.workers equals the batch size (e.batchSize) rather than the larger
env value; this ensures NewEnricher correctly integrates
audiobookEnrichBatchSize/audiobookEnrichWorkers capping logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 508a5630-5fa1-4d68-8f72-4e225d24627b

📥 Commits

Reviewing files that changed from the base of the PR and between 618424e and 8291be1.

📒 Files selected for processing (12)
  • internal/audiobooks/enrichment.go
  • internal/audiobooks/enrichment_test.go
  • internal/audiobooks/service.go
  • internal/audiobooks/service_test.go
  • internal/catalog/detail.go
  • internal/catalog/detail_audiobook_test.go
  • internal/config/db_loader.go
  • internal/config/db_loader_test.go
  • internal/scanner/audiobook_test.go
  • internal/scanner/scanner.go
  • migrations/sql/20260607161414_add_audiobookshelf_compat_enabled.sql
  • migrations/sql/20260608183000_enable_audiobookshelf_compat_default.sql

Comment thread internal/scanner/scanner.go Resolved
@Quick104
Quick104 merged commit 24d2103 into main Jun 8, 2026
1 check passed
@Quick104
Quick104 deleted the work/audiobook-fixes-main branch June 8, 2026 22:17
Quick104 pushed a commit that referenced this pull request Jun 11, 2026
* fix(audiobooks): improve poster enrichment throughput

* fix(audiobooks): enable ABS compat by default

* chore(audiobooks): remove stale feature flag setting

* fix(audiobooks): validate scoped scan roots

---------

Co-authored-by: rxwatcher <[email protected]>
Quick104 pushed a commit that referenced this pull request Jun 17, 2026
* fix(audiobooks): improve poster enrichment throughput

* fix(audiobooks): enable ABS compat by default

* chore(audiobooks): remove stale feature flag setting

* fix(audiobooks): validate scoped scan roots

---------

Co-authored-by: rxwatcher <[email protected]>
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.

2 participants