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:
+2
-1
@@ -12,12 +12,13 @@ type Album struct {
|
|||||||
AlbumArtist string
|
AlbumArtist string
|
||||||
Year int `idx:"Year"`
|
Year int `idx:"Year"`
|
||||||
Compilation bool
|
Compilation bool
|
||||||
Starred bool `idx:"Starred"`
|
Starred bool
|
||||||
PlayCount int
|
PlayCount int
|
||||||
PlayDate time.Time
|
PlayDate time.Time
|
||||||
Duration int
|
Duration int
|
||||||
Rating int
|
Rating int
|
||||||
Genre string
|
Genre string
|
||||||
|
StarredAt time.Time `idx:"Starred"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type MediaFile struct {
|
|||||||
PlayDate time.Time
|
PlayDate time.Time
|
||||||
Rating int
|
Rating int
|
||||||
Starred bool
|
Starred bool
|
||||||
|
StarredAt time.Time
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -106,9 +106,7 @@ func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *Dir
|
|||||||
Parent: al.ArtistId,
|
Parent: al.ArtistId,
|
||||||
PlayCount: int32(al.PlayCount),
|
PlayCount: int32(al.PlayCount),
|
||||||
UserRating: al.Rating,
|
UserRating: al.Rating,
|
||||||
}
|
Starred: al.StarredAt,
|
||||||
if al.Starred {
|
|
||||||
dir.Starred = al.UpdatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.Entries = make(Entries, len(tracks))
|
dir.Entries = make(Entries, len(tracks))
|
||||||
|
|||||||
+44
-48
@@ -46,59 +46,55 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func FromAlbum(al *domain.Album) Entry {
|
func FromAlbum(al *domain.Album) Entry {
|
||||||
c := Entry{}
|
e := Entry{}
|
||||||
c.Id = al.Id
|
e.Id = al.Id
|
||||||
c.Title = al.Name
|
e.Title = al.Name
|
||||||
c.IsDir = true
|
e.IsDir = true
|
||||||
c.Parent = al.ArtistId
|
e.Parent = al.ArtistId
|
||||||
c.Album = al.Name
|
e.Album = al.Name
|
||||||
c.Year = al.Year
|
e.Year = al.Year
|
||||||
c.Artist = al.AlbumArtist
|
e.Artist = al.AlbumArtist
|
||||||
c.Genre = al.Genre
|
e.Genre = al.Genre
|
||||||
c.CoverArt = al.CoverArtId
|
e.CoverArt = al.CoverArtId
|
||||||
if al.Starred {
|
e.Starred = al.StarredAt
|
||||||
c.Starred = al.UpdatedAt
|
e.PlayCount = int32(al.PlayCount)
|
||||||
}
|
e.Created = al.CreatedAt
|
||||||
c.PlayCount = int32(al.PlayCount)
|
e.AlbumId = al.Id
|
||||||
c.Created = al.CreatedAt
|
e.ArtistId = al.ArtistId
|
||||||
c.AlbumId = al.Id
|
e.UserRating = al.Rating
|
||||||
c.ArtistId = al.ArtistId
|
e.Duration = al.Duration
|
||||||
c.UserRating = al.Rating
|
return e
|
||||||
c.Duration = al.Duration
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromMediaFile(mf *domain.MediaFile) Entry {
|
func FromMediaFile(mf *domain.MediaFile) Entry {
|
||||||
c := Entry{}
|
e := Entry{}
|
||||||
c.Id = mf.Id
|
e.Id = mf.Id
|
||||||
c.Title = mf.Title
|
e.Title = mf.Title
|
||||||
c.IsDir = false
|
e.IsDir = false
|
||||||
c.Parent = mf.AlbumId
|
e.Parent = mf.AlbumId
|
||||||
c.Album = mf.Album
|
e.Album = mf.Album
|
||||||
c.Year = mf.Year
|
e.Year = mf.Year
|
||||||
c.Artist = mf.Artist
|
e.Artist = mf.Artist
|
||||||
c.Genre = mf.Genre
|
e.Genre = mf.Genre
|
||||||
c.Track = mf.TrackNumber
|
e.Track = mf.TrackNumber
|
||||||
c.Duration = mf.Duration
|
e.Duration = mf.Duration
|
||||||
c.Size = mf.Size
|
e.Size = mf.Size
|
||||||
c.Suffix = mf.Suffix
|
e.Suffix = mf.Suffix
|
||||||
c.BitRate = mf.BitRate
|
e.BitRate = mf.BitRate
|
||||||
if mf.Starred {
|
e.Starred = mf.StarredAt
|
||||||
c.Starred = mf.UpdatedAt
|
|
||||||
}
|
|
||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
c.CoverArt = mf.Id
|
e.CoverArt = mf.Id
|
||||||
}
|
}
|
||||||
c.ContentType = mf.ContentType()
|
e.ContentType = mf.ContentType()
|
||||||
c.Path = mf.Path
|
e.Path = mf.Path
|
||||||
c.PlayCount = int32(mf.PlayCount)
|
e.PlayCount = int32(mf.PlayCount)
|
||||||
c.DiscNumber = mf.DiscNumber
|
e.DiscNumber = mf.DiscNumber
|
||||||
c.Created = mf.CreatedAt
|
e.Created = mf.CreatedAt
|
||||||
c.AlbumId = mf.AlbumId
|
e.AlbumId = mf.AlbumId
|
||||||
c.ArtistId = mf.ArtistId
|
e.ArtistId = mf.ArtistId
|
||||||
c.Type = "music" // TODO Hardcoded for now
|
e.Type = "music" // TODO Hardcoded for now
|
||||||
c.UserRating = mf.Rating
|
e.UserRating = mf.Rating
|
||||||
return c
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromAlbums(albums domain.Albums) Entries {
|
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) {
|
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)
|
albums, err := g.albumRepo.GetStarred(qo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package persistence
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
)
|
)
|
||||||
@@ -49,7 +50,7 @@ func (r *albumRepository) GetAllIds() ([]string, error) {
|
|||||||
ids := make([]string, len(idMap))
|
ids := make([]string, len(idMap))
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for id, _ := range idMap {
|
for id := range idMap {
|
||||||
ids[i] = id
|
ids[i] = id
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,8 @@ func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error)
|
|||||||
|
|
||||||
func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) {
|
func (r *albumRepository) GetStarred(options domain.QueryOptions) (domain.Albums, error) {
|
||||||
var as = make(domain.Albums, 0)
|
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
|
return as, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -290,7 +290,13 @@ func (r *ledisRepository) loadRange(idxName string, min interface{}, max interfa
|
|||||||
maxS := toScore(max)
|
maxS := toScore(max)
|
||||||
|
|
||||||
idxKey := fmt.Sprintf("%s:idx:%s", r.table, idxName)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,12 @@ func (i *Importer) importLibrary() (err error) {
|
|||||||
if mf.UpdatedAt.Before(i.lastScan) {
|
if mf.UpdatedAt.Before(i.lastScan) {
|
||||||
continue
|
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 {
|
if err := i.mfRepo.Put(mf); err != nil {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
}
|
}
|
||||||
@@ -172,6 +178,12 @@ func (i *Importer) importLibrary() (err error) {
|
|||||||
if al.UpdatedAt.Before(i.lastScan) {
|
if al.UpdatedAt.Before(i.lastScan) {
|
||||||
continue
|
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 {
|
if err := i.albumRepo.Put(al); err != nil {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user