Skip to content

Commit

Permalink
Revert "Replace COUNT(DISTINCT primary_key) with COUNT(*)"
Browse files Browse the repository at this point in the history
Genres are required as part of the count queries, so filter by genres work
  • Loading branch information
deluan committed Nov 26, 2023
1 parent 8c8e1ea commit 28dc98d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions persistence/album_repository.go
Expand Up @@ -76,6 +76,7 @@ func artistFilter(field string, value interface{}) Sqlizer {

func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
sql := r.newSelectWithAnnotation("album.id")
sql = r.withGenres(sql) // Required for filtering by genre
return r.count(sql, options...)
}

Expand Down
1 change: 1 addition & 0 deletions persistence/artist_repository.go
Expand Up @@ -52,6 +52,7 @@ func (r *artistRepository) selectArtist(options ...model.QueryOptions) SelectBui

func (r *artistRepository) CountAll(options ...model.QueryOptions) (int64, error) {
sql := r.newSelectWithAnnotation("artist.id")
sql = r.withGenres(sql) // Required for filtering by genre
return r.count(sql, options...)
}

Expand Down
1 change: 1 addition & 0 deletions persistence/mediafile_repository.go
Expand Up @@ -40,6 +40,7 @@ func NewMediaFileRepository(ctx context.Context, o orm.QueryExecutor) *mediaFile

func (r *mediaFileRepository) CountAll(options ...model.QueryOptions) (int64, error) {
sql := r.newSelectWithAnnotation("media_file.id")
sql = r.withGenres(sql) // Required for filtering by genre
return r.count(sql, options...)
}

Expand Down
3 changes: 2 additions & 1 deletion persistence/sql_base_repository.go
Expand Up @@ -181,7 +181,8 @@ func (r sqlRepository) exists(existsQuery SelectBuilder) (bool, error) {

func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
countQuery = countQuery.
RemoveColumns().Columns("count(*) as count").From(r.tableName)
RemoveColumns().Columns("count(distinct " + r.tableName + ".id) as count").
From(r.tableName)
countQuery = r.applyFilters(countQuery, options...)
var res struct{ Count int64 }
err := r.queryOne(countQuery, &res)
Expand Down

0 comments on commit 28dc98d

Please sign in to comment.