use map to de-duplicate playlist tracks
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
@@ -340,22 +339,20 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
|||||||
} else {
|
} else {
|
||||||
m.App.Config.Application.DefaultPlaylistID = id
|
m.App.Config.Application.DefaultPlaylistID = id
|
||||||
if sp.SkipDuplicates {
|
if sp.SkipDuplicates {
|
||||||
var filterTrackIDs []string
|
|
||||||
go func() {
|
go func() {
|
||||||
|
currentTrackIDs := make(map[string]struct{})
|
||||||
if selectedPlaylist, err := m.App.ServerManager.Server.GetPlaylist(id); err != nil {
|
if selectedPlaylist, err := m.App.ServerManager.Server.GetPlaylist(id); err != nil {
|
||||||
log.Printf("error getting playlist: %s", err.Error())
|
log.Printf("error getting playlist: %s", err.Error())
|
||||||
} else {
|
} else {
|
||||||
var trackIDsInPaylist []string
|
|
||||||
|
|
||||||
for _, track := range selectedPlaylist.Tracks {
|
for _, track := range selectedPlaylist.Tracks {
|
||||||
trackIDsInPaylist = append(trackIDsInPaylist, track.ID)
|
currentTrackIDs[track.ID] = struct{}{}
|
||||||
}
|
}
|
||||||
filterTrackIDs = sharedutil.FilterSlice(trackIDs, func(trackID string) bool {
|
filterTrackIDs := sharedutil.FilterSlice(trackIDs, func(trackID string) bool {
|
||||||
return !slices.Contains(trackIDsInPaylist, trackID)
|
_, ok := currentTrackIDs[trackID]
|
||||||
|
return !ok
|
||||||
})
|
})
|
||||||
|
m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
|
||||||
}
|
}
|
||||||
m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
|
|
||||||
}()
|
}()
|
||||||
} else {
|
} else {
|
||||||
go m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
|
go m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
|
||||||
|
|||||||
Reference in New Issue
Block a user