Revert "Replace COUNT(DISTINCT primary_key) with COUNT(*)"
Genres are required as part of the count queries, so filter by genres work
This commit is contained in:
@@ -76,6 +76,7 @@ func artistFilter(field string, value interface{}) Sqlizer {
|
|||||||
|
|
||||||
func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||||
sql := r.newSelectWithAnnotation("album.id")
|
sql := r.newSelectWithAnnotation("album.id")
|
||||||
|
sql = r.withGenres(sql) // Required for filtering by genre
|
||||||
return r.count(sql, options...)
|
return r.count(sql, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func (r *artistRepository) selectArtist(options ...model.QueryOptions) SelectBui
|
|||||||
|
|
||||||
func (r *artistRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
func (r *artistRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||||
sql := r.newSelectWithAnnotation("artist.id")
|
sql := r.newSelectWithAnnotation("artist.id")
|
||||||
|
sql = r.withGenres(sql) // Required for filtering by genre
|
||||||
return r.count(sql, options...)
|
return r.count(sql, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ func NewMediaFileRepository(ctx context.Context, o orm.QueryExecutor) *mediaFile
|
|||||||
|
|
||||||
func (r *mediaFileRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
func (r *mediaFileRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||||
sql := r.newSelectWithAnnotation("media_file.id")
|
sql := r.newSelectWithAnnotation("media_file.id")
|
||||||
|
sql = r.withGenres(sql) // Required for filtering by genre
|
||||||
return r.count(sql, options...)
|
return r.count(sql, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,8 @@ func (r sqlRepository) exists(existsQuery SelectBuilder) (bool, error) {
|
|||||||
|
|
||||||
func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
|
func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
|
||||||
countQuery = countQuery.
|
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...)
|
countQuery = r.applyFilters(countQuery, options...)
|
||||||
var res struct{ Count int64 }
|
var res struct{ Count int64 }
|
||||||
err := r.queryOne(countQuery, &res)
|
err := r.queryOne(countQuery, &res)
|
||||||
|
|||||||
Reference in New Issue
Block a user