Add guard for empty ASIN in audiobook matcher

Prevents empty ASIN values from matching all library books by adding an early return in findPlexMatch(). Updates documentation to describe the critical bug, its impact, and the implemented fix. This resolves a major issue where AI recommendations were incorrectly filtered out due to empty ASINs matching every record.
This commit is contained in:
kikootwo
2026-01-28 14:28:03 -05:00
parent 12c0305a4b
commit 3290ebbc9d
3 changed files with 118 additions and 1 deletions
+19
View File
@@ -41,6 +41,25 @@ export interface AudiobookMatchResult {
export async function findPlexMatch(
audiobook: AudiobookMatchInput
): Promise<AudiobookMatchResult | null> {
// Early return if no ASIN provided (prevents empty string matching all records)
if (!audiobook.asin || audiobook.asin.trim() === '') {
logger.debug('Matcher result', {
MATCHER: {
input: {
title: audiobook.title,
author: audiobook.author,
narrator: audiobook.narrator || null,
asin: audiobook.asin,
},
candidatesFound: 0,
matchType: 'no_asin_provided',
matched: false,
result: null,
}
});
return null;
}
// Query plex_library directly by ASIN (indexed O(1) lookup)
// Check both dedicated asin field and plexGuid for backward compatibility
const plexBooks = await prisma.plexLibrary.findMany({