feat(artist): add library ID filtering for artists in repository and update resource filtering logic

Signed-off-by: Deluan <deluan@navidrome.org>

# Conflicts:
#	persistence/artist_repository.go
This commit is contained in:
Deluan 2025-06-26 12:37:22 -04:00
commit 4b107b213c
2 changed files with 17 additions and 6 deletions

View file

@ -113,11 +113,12 @@ func NewArtistRepository(ctx context.Context, db dbx.Builder) model.ArtistReposi
r.indexGroups = utils.ParseIndexGroups(conf.Server.IndexGroups)
r.tableName = "artist" // To be used by the idFilter below
r.registerModel(&model.Artist{}, map[string]filterFunc{
"id": idFilter(r.tableName),
"name": fullTextFilter(r.tableName, "mbz_artist_id"),
"starred": booleanFilter,
"role": roleFilter,
"missing": booleanFilter,
"id": idFilter(r.tableName),
"name": fullTextFilter(r.tableName, "mbz_artist_id"),
"starred": booleanFilter,
"role": roleFilter,
"missing": booleanFilter,
"library_id": artistLibraryFilter,
})
r.setSortMappings(map[string]string{
"name": "order_artist_name",
@ -143,6 +144,16 @@ func roleFilter(_ string, role any) Sqlizer {
return Eq{"1": 2}
}
// artistLibraryFilter handles filtering artists by library_id through the library_artist junction table
func artistLibraryFilter(_ string, value any) Sqlizer {
// Use a subquery with Eq to properly handle array parameters
subquery := Select("1").From("library_artist la").Where(And{
Expr("la.artist_id = artist.id"),
Eq{"la.library_id": value},
})
return Expr("EXISTS (?)", subquery)
}
func (r *artistRepository) selectArtist(options ...model.QueryOptions) SelectBuilder {
query := r.newSelect(options...).Columns("artist.*")
query = r.withAnnotation(query, "artist.id")

View file

@ -21,7 +21,7 @@ const getSelectedLibraries = () => {
// Function to apply library filtering to appropriate resources
const applyLibraryFilter = (resource, params) => {
// Content resources that should be filtered by selected libraries
const filteredResources = ['album', 'song', 'playlistTrack']
const filteredResources = ['album', 'song', 'artist', 'playlistTrack']
// Get selected libraries from localStorage
const selectedLibraries = getSelectedLibraries()