Match Top Songs by mbid, add indexes to media_file
This commit is contained in:
+21
-11
@@ -149,23 +149,33 @@ func (e *externalInfo) TopSongs(ctx context.Context, artist string, count int) (
|
|||||||
}
|
}
|
||||||
var songs model.MediaFiles
|
var songs model.MediaFiles
|
||||||
for _, t := range tracks {
|
for _, t := range tracks {
|
||||||
mfs, err := e.ds.MediaFile(ctx).GetAll(model.QueryOptions{
|
mf, err := e.findMatchingTrack(ctx, artist, t.Name, t.MBID)
|
||||||
Filters: squirrel.And{
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
songs = append(songs, *mf)
|
||||||
|
}
|
||||||
|
return songs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *externalInfo) findMatchingTrack(ctx context.Context, artist, title, mbid string) (*model.MediaFile, error) {
|
||||||
|
mfs, err := e.ds.MediaFile(ctx).GetAll(model.QueryOptions{
|
||||||
|
Filters: squirrel.Or{
|
||||||
|
squirrel.And{
|
||||||
squirrel.Or{
|
squirrel.Or{
|
||||||
squirrel.Like{"artist": artist},
|
squirrel.Like{"artist": artist},
|
||||||
squirrel.Like{"album_artist": artist},
|
squirrel.Like{"album_artist": artist},
|
||||||
},
|
},
|
||||||
squirrel.Like{"title": t.Name},
|
squirrel.Like{"title": title},
|
||||||
},
|
},
|
||||||
Sort: "year",
|
squirrel.Like{"mbz_track_id": mbid},
|
||||||
Order: "asc",
|
},
|
||||||
})
|
Sort: "mbz_track_id desc, year asc",
|
||||||
if err != nil || len(mfs) == 0 {
|
})
|
||||||
continue
|
if err != nil || len(mfs) == 0 {
|
||||||
}
|
return nil, model.ErrNotFound
|
||||||
songs = append(songs, mfs[0])
|
|
||||||
}
|
}
|
||||||
return songs, nil
|
return &mfs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *externalInfo) ArtistInfo(ctx context.Context, id string) (*model.ArtistInfo, error) {
|
func (e *externalInfo) ArtistInfo(ctx context.Context, id string) (*model.ArtistInfo, error) {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/pressly/goose"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
goose.AddMigration(Up20201021093209, Down20201021093209)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Up20201021093209(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec(`
|
||||||
|
create index if not exists media_file_artist
|
||||||
|
on media_file (artist);
|
||||||
|
create index if not exists media_file_album_artist
|
||||||
|
on media_file (album_artist);
|
||||||
|
create index if not exists media_file_mbz_track_id
|
||||||
|
on media_file (mbz_track_id);
|
||||||
|
`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Down20201021093209(tx *sql.Tx) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user