mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-11 07:41:06 +03:00
go tidy
This commit is contained in:
parent
5a41fb13b8
commit
6bbb0dae15
@ -184,24 +184,24 @@ func handleAlbum(matchResults map[string]string, ret []interface{}, cds *content
|
|||||||
func handleGenre(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o contentDirectoryObject, host string) ([]interface{}, error) {
|
func handleGenre(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o contentDirectoryObject, host string) ([]interface{}, error) {
|
||||||
if matchResults["GenreArtist"] != "" {
|
if matchResults["GenreArtist"] != "" {
|
||||||
/*
|
/*
|
||||||
SELECT * FROM media_file WHERE
|
SELECT * FROM media_file WHERE
|
||||||
EXISTS (
|
EXISTS (
|
||||||
SELECT 1 FROM json_each(tags, '$.genre')
|
SELECT 1 FROM json_each(tags, '$.genre')
|
||||||
WHERE json_extract(value, '$.id') == '7bLYq0Np81m1Wgy5N31nuG'
|
WHERE json_extract(value, '$.id') == '7bLYq0Np81m1Wgy5N31nuG'
|
||||||
|
)
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM json_each(participants, '$.artist')
|
||||||
|
WHERE json_extract(value, '$.id') == '4CBFO1ymQXgsbXQgV2aPMI'
|
||||||
)
|
)
|
||||||
AND EXISTS (
|
LIMIT 100
|
||||||
SELECT 1 FROM json_each(participants, '$.artist')
|
|
||||||
WHERE json_extract(value, '$.id') == '4CBFO1ymQXgsbXQgV2aPMI'
|
|
||||||
)
|
|
||||||
LIMIT 100
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
thisFilter := squirrel.And{
|
thisFilter := squirrel.And{
|
||||||
persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
||||||
squirrel.Eq{"key": "id"},
|
squirrel.Eq{"key": "id"},
|
||||||
squirrel.Eq{"value": matchResults["Genre"]},
|
squirrel.Eq{"value": matchResults["Genre"]},
|
||||||
}),
|
}),
|
||||||
persistence.Exists("json_tree(participants, '$.artist')", squirrel.And{
|
persistence.Exists("json_tree(participants, '$.artist')", squirrel.And{
|
||||||
squirrel.Eq{"key": "id"},
|
squirrel.Eq{"key": "id"},
|
||||||
squirrel.Eq{"value": matchResults["GenreArtist"]},
|
squirrel.Eq{"value": matchResults["GenreArtist"]},
|
||||||
}),
|
}),
|
||||||
@ -216,26 +216,26 @@ func handleGenre(matchResults map[string]string, ret []interface{}, cds *content
|
|||||||
} else if matchResults["Genre"] != "" {
|
} else if matchResults["Genre"] != "" {
|
||||||
if matchResults["GenreArtist"] == "" {
|
if matchResults["GenreArtist"] == "" {
|
||||||
/*
|
/*
|
||||||
// slightly cleaner query:
|
// slightly cleaner query:
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
json_extract(a.value, '$.name') artist_name,
|
json_extract(a.value, '$.name') artist_name,
|
||||||
json_extract(a.value, '$.id') artist_id,
|
json_extract(a.value, '$.id') artist_id,
|
||||||
COUNT(*)
|
COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
media_file f,
|
media_file f,
|
||||||
json_each(f.tags, '$.genre') as g,
|
json_each(f.tags, '$.genre') as g,
|
||||||
json_each(f.participants, '$.artist') as a
|
json_each(f.participants, '$.artist') as a
|
||||||
WHERE
|
WHERE
|
||||||
json_extract(g.value, '$.id') = '7bLYq0Np81m1Wgy5N31nuG'
|
json_extract(g.value, '$.id') = '7bLYq0Np81m1Wgy5N31nuG'
|
||||||
GROUP BY artist_id;
|
GROUP BY artist_id;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
thisFilter := persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
thisFilter := persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
||||||
squirrel.Eq{"key": "id"},
|
squirrel.Eq{"key": "id"},
|
||||||
squirrel.Eq{"value": matchResults["Genre"]},
|
squirrel.Eq{"value": matchResults["Genre"]},
|
||||||
})
|
})
|
||||||
mediaFiles, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: thisFilter })
|
mediaFiles, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: thisFilter})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error retrieving artists for genre: %+v", err)
|
fmt.Printf("Error retrieving artists for genre: %+v", err)
|
||||||
@ -251,7 +251,7 @@ func handleGenre(matchResults map[string]string, ret []interface{}, cds *content
|
|||||||
}
|
}
|
||||||
|
|
||||||
for artistId := range artistsFound {
|
for artistId := range artistsFound {
|
||||||
child := contentDirectoryObject {
|
child := contentDirectoryObject{
|
||||||
Path: path.Join(o.Path, artistsFound[artistId]),
|
Path: path.Join(o.Path, artistsFound[artistId]),
|
||||||
Id: path.Join(o.Path, artistId),
|
Id: path.Join(o.Path, artistId),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user