fix: address race conditions and design issues in PlaylistGenerator

Rename PlaylistInfo.OwnerUserID to OwnerUsername so plugins provide
usernames instead of internal user IDs, with server-side resolution via
FindByUsername. Fix race condition on playlistGenerators map by using
write lock in startPlaylistGenerators and moving map access inside the
lock in unloadPlugin/Stop. Add context and WaitGroup to the orchestrator
for proper cancellation and goroutine tracking. Include owner_id in the
plugin playlist unique index. Use SetTracks instead of direct assignment
to refresh playlist duration/size/song count stats.
This commit is contained in:
Deluan 2026-03-05 09:01:33 -05:00
commit a8a336de33
10 changed files with 71 additions and 42 deletions

View file

@ -21,16 +21,16 @@ func (t *testPlaylistGenerator) GetPlaylists(_ pg.GetPlaylistsRequest) (pg.GetPl
return pg.GetPlaylistsResponse{}, fmt.Errorf("%s", errMsg)
}
// Get the owner user ID from config (defaults to "user-1")
ownerID := "user-1"
if id, ok := pdk.GetConfig("owner_id"); ok && id != "" {
ownerID = id
// Get the owner username from config (defaults to "admin")
ownerUsername := "admin"
if u, ok := pdk.GetConfig("owner_username"); ok && u != "" {
ownerUsername = u
}
return pg.GetPlaylistsResponse{
Playlists: []pg.PlaylistInfo{
{ID: "daily-mix-1", OwnerUserID: ownerID},
{ID: "daily-mix-2", OwnerUserID: ownerID},
{ID: "daily-mix-1", OwnerUsername: ownerUsername},
{ID: "daily-mix-2", OwnerUsername: ownerUsername},
},
RefreshInterval: 0, // No re-discovery in tests
}, nil