Simplify normalized AlbumPlayCountMode calc

This commit is contained in:
Deluan 2024-05-09 08:13:42 -04:00
parent 747069b229
commit 09d1fd0658
2 changed files with 2 additions and 5 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"strings"
. "github.com/Masterminds/squirrel"
@ -22,12 +21,10 @@ type albumRepository struct {
type dbAlbum struct {
*model.Album `structs:",flatten"`
Discs string `structs:"-" json:"discs"`
PlayCount float64 `structs:"-" json:"play_count"`
Discs string `structs:"-" json:"discs"`
}
func (a *dbAlbum) PostScan() error {
a.Album.PlayCount = int64(math.Round(a.PlayCount))
if a.Discs != "" {
return json.Unmarshal([]byte(a.Discs), &a.Album.Discs)
}

View File

@ -28,7 +28,7 @@ func (r sqlRepository) newSelectWithAnnotation(idField string, options ...model.
"play_date",
)
if conf.Server.AlbumPlayCountMode == consts.AlbumPlayCountModeNormalized && r.tableName == "album" {
query = query.Columns("coalesce(round(cast(play_count as float) / coalesce(song_count, 1), 1), 0) as play_count")
query = query.Columns("round(coalesce(round(cast(play_count as float) / coalesce(song_count, 1), 1), 0)) as play_count")
} else {
query = query.Columns("coalesce(play_count, 0) as play_count")
}