Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursively refresh playlist tracks within smart playlist rules #3018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

reillymc
Copy link

Fixes #3017

This PR ensure that when a smart playlist is refreshed, the playlists used in its rules also have their tracks refreshed first.

This is my first time diving into the Navidrome codebase and using the Go language, so if there is anything I need to do to improve the code here please let me know and I'll be happy to fix it up!

@reillymc reillymc force-pushed the smart-playlist-recursive-track-refresh branch from 08b12b8 to 2863c61 Compare May 12, 2024 07:12
Copy link

Download the artifacts for this pull request:

Copy link
Member

@deluan deluan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job for a first Go AND Navidrome contribution. I admit this codebase can be daunting.

Anyway, thanks and take a look at my comments below.

Comment on lines +292 to +307
case Any:
for _, rules := range rule {
ids = extractPlaylistIds(rules, ids)
}
case All:
for _, rules := range rule {
ids = extractPlaylistIds(rules, ids)
}
case InPlaylist:
if id, ok = rule["id"].(string); ok {
ids = append(ids, id)
}
case NotInPlaylist:
if id, ok = rule["id"].(string); ok {
ids = append(ids, id)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case Any:
for _, rules := range rule {
ids = extractPlaylistIds(rules, ids)
}
case All:
for _, rules := range rule {
ids = extractPlaylistIds(rules, ids)
}
case InPlaylist:
if id, ok = rule["id"].(string); ok {
ids = append(ids, id)
}
case NotInPlaylist:
if id, ok = rule["id"].(string); ok {
ids = append(ids, id)
}
case Any, All:
for _, rules := range rule {
ids = extractPlaylistIds(rules, ids)
}
case InPlaylist, NotInPlaylist:
if id, ok = rule["id"].(string); ok {
ids = append(ids, id)
}

@@ -275,3 +283,29 @@ func inList(m map[string]interface{}, negate bool) (sql string, args []interface
return "media_file.id IN (" + subQText + ")", subQArgs, nil
}
}

func extractPlaylistIds(inputRule interface{}, ids []string) []string {
var id string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are never returning the ids slice, you are basically mutating the slice passed. Try to not mutate the param and properly returning the new slice.

@@ -36,6 +40,10 @@ func (any Any) MarshalJSON() ([]byte, error) {
return marshalConjunction("any", any)
}

func (any Any) ChildPlaylistIds() (ids []string) {
return extractPlaylistIds(any, ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that's why it is working, because you are passing the response as a param to extractPlaylistIds. If we went with this design, extractPlaylistIds wouldn't need to return anything. But I rather not mutate arguments when possible.

log.Error(r.ctx, "Error loading child playlist", "id", pls.ID, "childId", id, err)
return false
}
r.refreshSmartPlaylist(childPls)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure if we want to refresh all children playlists like this, this could have a performance impact. Did you test it with large playlists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Smart playlists do not refetch tracks from child smart playlists used in rules
2 participants