From 4b107b213c09cc1d0517d1a2b393d91c3e8f781b Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 26 Jun 2025 12:37:22 -0400 Subject: [PATCH] feat(artist): add library ID filtering for artists in repository and update resource filtering logic Signed-off-by: Deluan # Conflicts: # persistence/artist_repository.go --- persistence/artist_repository.go | 21 ++++++++++++++++----- ui/src/dataProvider/wrapperDataProvider.js | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/persistence/artist_repository.go b/persistence/artist_repository.go index f5b892ba1..65b287e4c 100644 --- a/persistence/artist_repository.go +++ b/persistence/artist_repository.go @@ -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") diff --git a/ui/src/dataProvider/wrapperDataProvider.js b/ui/src/dataProvider/wrapperDataProvider.js index 74d68a5f4..8c03df555 100644 --- a/ui/src/dataProvider/wrapperDataProvider.js +++ b/ui/src/dataProvider/wrapperDataProvider.js @@ -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()