From 91647ed46f1eaeb30c6f71a466dfe38a3eaab420 Mon Sep 17 00:00:00 2001 From: Deluan Date: Mon, 4 May 2026 17:29:27 -0400 Subject: [PATCH] fix(scanner): skip library filter for empty user ID on fresh installs When no admin user exists (fresh DB), WithAdminUser falls back to model.User{ID: ""}. The empty ID bypassed neither the invalidUserId ("-1") check nor the IsAdmin check in applyLibraryFilter, causing Phase 3's GetTouchedAlbums to filter by user_id="" and find zero albums. The album refresh never ran, leaving multi-disc albums with incomplete folder_ids from Phase 1. Fix: treat empty user ID the same as invalidUserId in applyLibraryFilter, skipping the library filter entirely. This is more targeted than making the fallback user admin, which would affect other callers like Phase 4 playlist import. Signed-off-by: Deluan --- persistence/sql_base_repository.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence/sql_base_repository.go b/persistence/sql_base_repository.go index fd263d37b..98aa66158 100644 --- a/persistence/sql_base_repository.go +++ b/persistence/sql_base_repository.go @@ -205,8 +205,8 @@ func libraryIdFilter(_ string, value any) Sqlizer { func (r sqlRepository) applyLibraryFilter(sq SelectBuilder, tableName ...string) SelectBuilder { user := loggedUser(r.ctx) - // If the user is an admin, or the user ID is invalid (e.g., when no user is logged in), skip the library filter - if user.IsAdmin || user.ID == invalidUserId { + // If the user is an admin, or the user ID is empty/invalid (e.g., when no user is logged in), skip the library filter + if user.IsAdmin || user.ID == "" || user.ID == invalidUserId { return sq }