Skip to content

🎧 Your Personal Streaming Service

Simplify normalized AlbumPlayCountMode calc

Deluan09d1fd065856
diff --git a/persistence/album_repository.go b/persistence/album_repository.go
index e23d18974..862852d7e 100644
--- a/persistence/album_repository.go
+++ b/persistence/album_repository.go
@@ -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)
}
diff --git a/persistence/sql_annotations.go b/persistence/sql_annotations.go
index a8eef3f2f..77dc816c2 100644
--- a/persistence/sql_annotations.go
+++ b/persistence/sql_annotations.go
@@ -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")
}