[PR #4976] Fix case-insensitive lookup for series and authors during import #4391

Open
opened 2026-04-25 00:19:34 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf/pull/4976
Author: @rbennion
Created: 1/9/2026
Status: 🔄 Open

Base: masterHead: fix/case-insensitive-series-author-lookup


📝 Commits (1)

  • 0ed641f Fix case-insensitive lookup for series and authors during import

📊 Changes

1 file changed (+6 additions, -2 deletions)

View changed files

📝 server/Database.js (+6 -2)

📄 Description

Brief summary

Prevent duplicate series and authors from being created when names differ only in casing (e.g., "Harry Potter" vs "harry potter") during library scanning/import.

Which issue is fixed?

Fixes #4255

Related to #4033 and #4934

In-depth Description

When importing books, the code has two paths for looking up existing series/authors:

  1. Database fallback (getByNameAndLibrary) - uses fn('lower', col('name')) for case-insensitive matching
  2. Filter data cache - was using se.name === seriesName for case-sensitive matching

This inconsistency meant:

  • First scan (no filter data loaded): Case-insensitive lookup → correct
  • Subsequent scans (filter data cached): Case-sensitive lookup → creates duplicates!

The fix: Changed both getSeriesIdByName and getAuthorIdByName in Database.js to use case-insensitive comparison when using the filter data cache:

// Before (buggy):
return this.libraryFilterData[libraryId].series.find((se) => se.name === seriesName)?.id || null

// After (fixed):
const seriesNameLower = seriesName.toLowerCase()
return this.libraryFilterData[libraryId].series.find((se) => se.name.toLowerCase() === seriesNameLower)?.id || null

This affects both series and authors, preventing duplicates for both during import.

How have you tested this?

  1. All 315 existing unit tests pass
  2. Manual testing steps:
    • Import a book with series "Harry Potter"
    • Import another book with series "harry potter"
    • Both books now correctly group under the same series (using the first casing encountered)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf/pull/4976 **Author:** [@rbennion](https://github.com/rbennion) **Created:** 1/9/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/case-insensitive-series-author-lookup` --- ### 📝 Commits (1) - [`0ed641f`](https://github.com/advplyr/audiobookshelf/commit/0ed641f0b15ed854b2aa804a143e6ce0fd91df43) Fix case-insensitive lookup for series and authors during import ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `server/Database.js` (+6 -2) </details> ### 📄 Description ## Brief summary Prevent duplicate series and authors from being created when names differ only in casing (e.g., "Harry Potter" vs "harry potter") during library scanning/import. ## Which issue is fixed? Fixes #4255 Related to #4033 and #4934 ## In-depth Description When importing books, the code has two paths for looking up existing series/authors: 1. **Database fallback** (`getByNameAndLibrary`) - uses `fn('lower', col('name'))` for case-insensitive matching ✅ 2. **Filter data cache** - was using `se.name === seriesName` for case-sensitive matching ❌ This inconsistency meant: - First scan (no filter data loaded): Case-insensitive lookup → correct - Subsequent scans (filter data cached): Case-sensitive lookup → creates duplicates! **The fix:** Changed both `getSeriesIdByName` and `getAuthorIdByName` in `Database.js` to use case-insensitive comparison when using the filter data cache: ```javascript // Before (buggy): return this.libraryFilterData[libraryId].series.find((se) => se.name === seriesName)?.id || null // After (fixed): const seriesNameLower = seriesName.toLowerCase() return this.libraryFilterData[libraryId].series.find((se) => se.name.toLowerCase() === seriesNameLower)?.id || null ``` This affects both series and authors, preventing duplicates for both during import. ## How have you tested this? 1. All 315 existing unit tests pass 2. Manual testing steps: - Import a book with series "Harry Potter" - Import another book with series "harry potter" - Both books now correctly group under the same series (using the first casing encountered) 🤖 Generated with [Claude Code](https://claude.ai/code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-25 00:19:34 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#4391