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,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user