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 <deluan@navidrome.org>
This commit is contained in:
Deluan 2026-05-04 17:29:27 -04:00
parent f48416685f
commit 91647ed46f

View File

@ -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
}