Skip to content

Commit

Permalink
Fix aggregated values (count, size, duration) in roll-up queries
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 20, 2021
1 parent 054b5ea commit 21cd50d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions persistence/album_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ func (r *albumRepository) refresh(ids ...string) error {
group_concat(f.artist_id, ' ') as song_artist_ids,
group_concat(f.album_artist_id, ' ') as album_artist_ids,
group_concat(f.year, ' ') as years,
group_concat(mg.genre_id, ' ') as genre_ids`).
(select group_concat(genre_id, ' ') from media_file_genres where media_file_id = f.id) as genre_ids`).
From("media_file f").
LeftJoin("album a on f.album_id = a.id").
LeftJoin("media_file_genres mg on mg.media_file_id = f.id").
Where(Eq{"f.album_id": ids}).GroupBy("f.album_id")
err := r.queryAll(sel, &albums)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions persistence/artist_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ func (r *artistRepository) refresh(ids ...string) error {
"group_concat(f.mbz_album_artist_id , ' ') as mbz_artist_id",
"f.sort_album_artist_name as sort_artist_name", "f.order_album_artist_name as order_artist_name",
"sum(f.song_count) as song_count", "sum(f.size) as size",
"group_concat(ag.genre_id, ' ') as genre_ids").
"(select group_concat(genre_id, ' ') from album_genres where album_id = f.id) as genre_ids").
From("album f").
LeftJoin("artist a on f.album_artist_id = a.id").
LeftJoin("album_genres ag on ag.album_id = f.id").
Where(Eq{"f.album_artist_id": ids}).
GroupBy("f.album_artist_id").OrderBy("f.id")
err := r.queryAll(sel, &artists)
Expand Down

0 comments on commit 21cd50d

Please sign in to comment.