mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-24 10:59:47 +01:00
refactor: change ArtistRepository.GetIndex to accept multiple library IDs
Updated the GetIndex method signature to accept a slice of library IDs instead of a single ID, enabling support for filtering artists across multiple libraries simultaneously. Changes include: - Modified ArtistRepository interface in model/artist.go - Updated implementation in persistence/artist_repository.go with improved library filtering logic - Refactored Subsonic API browsing.go to use new selectedMusicFolderIds helper - Added comprehensive test coverage for multiple library scenarios - Updated mock repository implementation for testing This change improves flexibility for multi-library operations while maintaining backward compatibility through the selectedMusicFolderIds helper function.
This commit is contained in:
parent
64159d715a
commit
c5b7857fef
6 changed files with 57 additions and 45 deletions
|
|
@ -30,7 +30,7 @@ func (api *Router) GetMusicFolders(r *http.Request) (*responses.Subsonic, error)
|
|||
return response, nil
|
||||
}
|
||||
|
||||
func (api *Router) getArtist(r *http.Request, libId int, ifModifiedSince time.Time) (model.ArtistIndexes, int64, error) {
|
||||
func (api *Router) getArtist(r *http.Request, libIds []int, ifModifiedSince time.Time) (model.ArtistIndexes, int64, error) {
|
||||
ctx := r.Context()
|
||||
|
||||
lastScanStr, err := api.ds.Property(ctx).DefaultGet(consts.LastScanStartTimeKey, "")
|
||||
|
|
@ -45,13 +45,13 @@ func (api *Router) getArtist(r *http.Request, libId int, ifModifiedSince time.Ti
|
|||
|
||||
var indexes model.ArtistIndexes
|
||||
if lastScan.After(ifModifiedSince) {
|
||||
indexes, err = api.ds.Artist(ctx).GetIndex(false, libId, model.RoleAlbumArtist)
|
||||
indexes, err = api.ds.Artist(ctx).GetIndex(false, libIds, model.RoleAlbumArtist)
|
||||
if err != nil {
|
||||
log.Error(ctx, "Error retrieving Indexes", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
if len(indexes) == 0 {
|
||||
log.Debug(ctx, "No artists found in library", "libId", libId)
|
||||
log.Debug(ctx, "No artists found in library", "libId", libIds)
|
||||
return nil, 0, newError(responses.ErrorDataNotFound, "Library not found or empty")
|
||||
}
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ func (api *Router) getArtist(r *http.Request, libId int, ifModifiedSince time.Ti
|
|||
return indexes, lastScan.UnixMilli(), err
|
||||
}
|
||||
|
||||
func (api *Router) getArtistIndex(r *http.Request, libId int, ifModifiedSince time.Time) (*responses.Indexes, error) {
|
||||
indexes, modified, err := api.getArtist(r, libId, ifModifiedSince)
|
||||
func (api *Router) getArtistIndex(r *http.Request, libIds []int, ifModifiedSince time.Time) (*responses.Indexes, error) {
|
||||
indexes, modified, err := api.getArtist(r, libIds, ifModifiedSince)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -78,8 +78,8 @@ func (api *Router) getArtistIndex(r *http.Request, libId int, ifModifiedSince ti
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func (api *Router) getArtistIndexID3(r *http.Request, libId int, ifModifiedSince time.Time) (*responses.Artists, error) {
|
||||
indexes, modified, err := api.getArtist(r, libId, ifModifiedSince)
|
||||
func (api *Router) getArtistIndexID3(r *http.Request, libIds []int, ifModifiedSince time.Time) (*responses.Artists, error) {
|
||||
indexes, modified, err := api.getArtist(r, libIds, ifModifiedSince)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -99,10 +99,10 @@ func (api *Router) getArtistIndexID3(r *http.Request, libId int, ifModifiedSince
|
|||
|
||||
func (api *Router) GetIndexes(r *http.Request) (*responses.Subsonic, error) {
|
||||
p := req.Params(r)
|
||||
musicFolderId := p.IntOr("musicFolderId", 0) // 0 means all accessible libraries
|
||||
musicFolderIds, _ := selectedMusicFolderIds(r, false)
|
||||
ifModifiedSince := p.TimeOr("ifModifiedSince", time.Time{})
|
||||
|
||||
res, err := api.getArtistIndex(r, musicFolderId, ifModifiedSince)
|
||||
res, err := api.getArtistIndex(r, musicFolderIds, ifModifiedSince)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -113,10 +113,9 @@ func (api *Router) GetIndexes(r *http.Request) (*responses.Subsonic, error) {
|
|||
}
|
||||
|
||||
func (api *Router) GetArtists(r *http.Request) (*responses.Subsonic, error) {
|
||||
p := req.Params(r)
|
||||
musicFolderId := p.IntOr("musicFolderId", 0) // 0 means all accessible libraries
|
||||
musicFolderIds, _ := selectedMusicFolderIds(r, false)
|
||||
|
||||
res, err := api.getArtistIndexID3(r, musicFolderId, time.Time{})
|
||||
res, err := api.getArtistIndexID3(r, musicFolderIds, time.Time{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -482,6 +482,9 @@ func getUserAccessibleLibraries(ctx context.Context) []model.Library {
|
|||
return user.Libraries
|
||||
}
|
||||
|
||||
// selectedMusicFolderIds retrieves the music folder IDs from the request parameters.
|
||||
// If no IDs are provided, it returns all libraries the user has access to (based on the user found in the context).
|
||||
// If the parameter is required and not present, it returns an error.
|
||||
func selectedMusicFolderIds(r *http.Request, required bool) ([]int, error) {
|
||||
p := req.Params(r)
|
||||
musicFolderIds, err := p.Ints("musicFolderId")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue