Skip to content

Commit

Permalink
Simplify normalized AlbumPlayCountMode calc
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed May 9, 2024
1 parent 747069b commit 09d1fd0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions persistence/album_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"strings"

. "github.com/Masterminds/squirrel"
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion persistence/sql_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 09d1fd0

Please sign in to comment.