mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-18 21:07:44 +03:00
Small changes regarding StarredAt.
Making StarredAt more "precise", setting it to the time the change was detected. getStarred.view now returns albums ordered by StarredAt. loadRange method now take QueryOptions.Desc into account
This commit is contained in:
parent
4e3c848815
commit
db992a9941
@ -12,12 +12,13 @@ type Album struct {
|
||||
AlbumArtist string
|
||||
Year int `idx:"Year"`
|
||||
Compilation bool
|
||||
Starred bool `idx:"Starred"`
|
||||
Starred bool
|
||||
PlayCount int
|
||||
PlayDate time.Time
|
||||
Duration int
|
||||
Rating int
|
||||
Genre string
|
||||
StarredAt time.Time `idx:"Starred"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ type MediaFile struct {
|
||||
PlayDate time.Time
|
||||
Rating int
|
||||
Starred bool
|
||||
StarredAt time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
@ -106,9 +106,7 @@ func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *Dir
|
||||
Parent: al.ArtistId,
|
||||
PlayCount: int32(al.PlayCount),
|
||||
UserRating: al.Rating,
|
||||
}
|
||||
if al.Starred {
|
||||
dir.Starred = al.UpdatedAt
|
||||
Starred: al.StarredAt,
|
||||
}
|
||||
|
||||
dir.Entries = make(Entries, len(tracks))
|
||||
|
@ -46,59 +46,55 @@ var (
|
||||
)
|
||||
|
||||
func FromAlbum(al *domain.Album) Entry {
|
||||
c := Entry{}
|
||||
c.Id = al.Id
|
||||
c.Title = al.Name
|
||||
c.IsDir = true
|
||||
c.Parent = al.ArtistId
|
||||
c.Album = al.Name
|
||||
c.Year = al.Year
|
||||
c.Artist = al.AlbumArtist
|
||||
c.Genre = al.Genre
|
||||
c.CoverArt = al.CoverArtId
|
||||
if al.Starred {
|
||||
c.Starred = al.UpdatedAt
|
||||
}
|
||||
c.PlayCount = int32(al.PlayCount)
|
||||
c.Created = al.CreatedAt
|
||||
c.AlbumId = al.Id
|
||||
c.ArtistId = al.ArtistId
|
||||
c.UserRating = al.Rating
|
||||
c.Duration = al.Duration
|
||||
return c
|
||||
e := Entry{}
|
||||
e.Id = al.Id
|
||||
e.Title = al.Name
|
||||
e.IsDir = true
|
||||
e.Parent = al.ArtistId
|
||||
e.Album = al.Name
|
||||
e.Year = al.Year
|
||||
e.Artist = al.AlbumArtist
|
||||
e.Genre = al.Genre
|
||||
e.CoverArt = al.CoverArtId
|
||||
e.Starred = al.StarredAt
|
||||
e.PlayCount = int32(al.PlayCount)
|
||||
e.Created = al.CreatedAt
|
||||
e.AlbumId = al.Id
|
||||
e.ArtistId = al.ArtistId
|
||||
e.UserRating = al.Rating
|
||||
e.Duration = al.Duration
|
||||
return e
|
||||
}
|
||||
|
||||
func FromMediaFile(mf *domain.MediaFile) Entry {
|
||||
c := Entry{}
|
||||
c.Id = mf.Id
|
||||
c.Title = mf.Title
|
||||
c.IsDir = false
|
||||
c.Parent = mf.AlbumId
|
||||
c.Album = mf.Album
|
||||
c.Year = mf.Year
|
||||
c.Artist = mf.Artist
|
||||
c.Genre = mf.Genre
|
||||
c.Track = mf.TrackNumber
|
||||
c.Duration = mf.Duration
|
||||
c.Size = mf.Size
|
||||
c.Suffix = mf.Suffix
|
||||
c.BitRate = mf.BitRate
|
||||
if mf.Starred {
|
||||
c.Starred = mf.UpdatedAt
|
||||
}
|
||||
e := Entry{}
|
||||
e.Id = mf.Id
|
||||
e.Title = mf.Title
|
||||
e.IsDir = false
|
||||
e.Parent = mf.AlbumId
|
||||
e.Album = mf.Album
|
||||
e.Year = mf.Year
|
||||
e.Artist = mf.Artist
|
||||
e.Genre = mf.Genre
|
||||
e.Track = mf.TrackNumber
|
||||
e.Duration = mf.Duration
|
||||
e.Size = mf.Size
|
||||
e.Suffix = mf.Suffix
|
||||
e.BitRate = mf.BitRate
|
||||
e.Starred = mf.StarredAt
|
||||
if mf.HasCoverArt {
|
||||
c.CoverArt = mf.Id
|
||||
e.CoverArt = mf.Id
|
||||
}
|
||||
c.ContentType = mf.ContentType()
|
||||
c.Path = mf.Path
|
||||
c.PlayCount = int32(mf.PlayCount)
|
||||
c.DiscNumber = mf.DiscNumber
|
||||
c.Created = mf.CreatedAt
|
||||
c.AlbumId = mf.AlbumId
|
||||
c.ArtistId = mf.ArtistId
|
||||
c.Type = "music" // TODO Hardcoded for now
|
||||
c.UserRating = mf.Rating
|
||||
return c
|
||||
e.ContentType = mf.ContentType()
|
||||
e.Path = mf.Path
|
||||
e.PlayCount = int32(mf.PlayCount)
|
||||
e.DiscNumber = mf.DiscNumber
|
||||
e.Created = mf.CreatedAt
|
||||
e.AlbumId = mf.AlbumId
|
||||
e.ArtistId = mf.ArtistId
|
||||
e.Type = "music" // TODO Hardcoded for now
|
||||
e.UserRating = mf.Rating
|
||||
return e
|
||||
}
|
||||
|
||||
func FromAlbums(albums domain.Albums) Entries {
|
||||
|
@ -89,7 +89,7 @@ func (g *listGenerator) GetRandom(offset int, size int) (Entries, error) {
|
||||
}
|
||||
|
||||
func (g *listGenerator) GetStarred(offset int, size int) (Entries, error) {
|
||||
qo := domain.QueryOptions{Offset: offset, Size: size}
|
||||
qo := domain.QueryOptions{Offset: offset, Size: size, Desc: true}
|
||||
albums, err := g.albumRepo.GetStarred(qo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -2,6 +2,7 @@ package persistence
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/deluan/gosonic/domain"
|
||||
)
|
||||
@ -49,7 +50,7 @@ func (r *albumRepository) GetAllIds() ([]string, error) {
|
||||
ids := make([]string, len(idMap))
|
||||
|
||||
i := 0
|
||||
for id, _ := range idMap {
|
||||
for id := range idMap {
|
||||
ids[i] = id
|
||||
i++
|
||||
}
|
||||
@ -65,7 +66,8 @@ func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error)
|
||||
|
||||
func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) {
|
||||
var as = make(domain.Albums, 0)
|
||||
err := r.loadRange("Starred", true, true, &as, options)
|
||||
start := time.Time{}.Add(time.Duration(1) * time.Hour)
|
||||
err := r.loadRange("Starred", start, time.Now(), &as, options)
|
||||
return as, err
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,13 @@ func (r *ledisRepository) loadRange(idxName string, min interface{}, max interfa
|
||||
maxS := toScore(max)
|
||||
|
||||
idxKey := fmt.Sprintf("%s:idx:%s", r.table, idxName)
|
||||
resp, err := Db().ZRangeByScore([]byte(idxKey), minS, maxS, o.Offset, o.Size)
|
||||
var resp []ledis.ScorePair
|
||||
var err error
|
||||
if o.Desc {
|
||||
resp, err = Db().ZRevRangeByScore([]byte(idxKey), minS, maxS, o.Offset, o.Size)
|
||||
} else {
|
||||
resp, err = Db().ZRangeByScore([]byte(idxKey), minS, maxS, o.Offset, o.Size)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -153,6 +153,12 @@ func (i *Importer) importLibrary() (err error) {
|
||||
if mf.UpdatedAt.Before(i.lastScan) {
|
||||
continue
|
||||
}
|
||||
if mf.Starred {
|
||||
original, err := i.mfRepo.Get(mf.Id)
|
||||
if err != nil || !original.Starred {
|
||||
mf.StarredAt = mf.UpdatedAt
|
||||
}
|
||||
}
|
||||
if err := i.mfRepo.Put(mf); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
@ -172,6 +178,12 @@ func (i *Importer) importLibrary() (err error) {
|
||||
if al.UpdatedAt.Before(i.lastScan) {
|
||||
continue
|
||||
}
|
||||
if al.Starred {
|
||||
original, err := i.albumRepo.Get(al.Id)
|
||||
if err != nil || !original.Starred {
|
||||
al.StarredAt = al.UpdatedAt
|
||||
}
|
||||
}
|
||||
if err := i.albumRepo.Put(al); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user