mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-19 13:27:42 +03:00
fix: DB pagination
This commit is contained in:
parent
f5071d1614
commit
4f4af34595
@ -25,8 +25,7 @@ func NewAlbumRepository(ctx context.Context, o orm.Ormer) model.AlbumRepository
|
||||
}
|
||||
|
||||
func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||
sel := r.selectAlbum(options...)
|
||||
return r.count(sel, options...)
|
||||
return r.count(Select(), options...)
|
||||
}
|
||||
|
||||
func (r *albumRepository) Exists(id string) (bool, error) {
|
||||
|
@ -34,8 +34,7 @@ func (r *artistRepository) selectArtist(options ...model.QueryOptions) SelectBui
|
||||
}
|
||||
|
||||
func (r *artistRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||
sel := r.selectArtist(options...)
|
||||
return r.count(sel, options...)
|
||||
return r.count(Select(), options...)
|
||||
}
|
||||
|
||||
func (r *artistRepository) Exists(id string) (bool, error) {
|
||||
|
@ -43,6 +43,7 @@ func (r *sqlRepository) newSelectWithAnnotation(itemType, idField string, option
|
||||
func (r *sqlRepository) newSelect(options ...model.QueryOptions) SelectBuilder {
|
||||
sq := Select().From(r.tableName)
|
||||
sq = r.applyOptions(sq, options...)
|
||||
sq = r.applyFilters(sq, options...)
|
||||
return sq
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ func (r *sqlRepository) applyOptions(sq SelectBuilder, options ...model.QueryOpt
|
||||
sq = sq.Limit(uint64(options[0].Max))
|
||||
}
|
||||
if options[0].Offset > 0 {
|
||||
sq = sq.Offset(uint64(options[0].Max))
|
||||
sq = sq.Offset(uint64(options[0].Offset))
|
||||
}
|
||||
if options[0].Sort != "" {
|
||||
if options[0].Order == "desc" {
|
||||
@ -61,9 +62,13 @@ func (r *sqlRepository) applyOptions(sq SelectBuilder, options ...model.QueryOpt
|
||||
sq = sq.OrderBy(toSnakeCase(options[0].Sort))
|
||||
}
|
||||
}
|
||||
if options[0].Filters != nil {
|
||||
sq = sq.Where(options[0].Filters)
|
||||
}
|
||||
}
|
||||
return sq
|
||||
}
|
||||
|
||||
func (r *sqlRepository) applyFilters(sq SelectBuilder, options ...model.QueryOptions) SelectBuilder {
|
||||
if len(options) > 0 && options[0].Filters != nil {
|
||||
sq = sq.Where(options[0].Filters)
|
||||
}
|
||||
return sq
|
||||
}
|
||||
@ -119,7 +124,7 @@ func (r sqlRepository) exists(existsQuery SelectBuilder) (bool, error) {
|
||||
|
||||
func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
|
||||
countQuery = countQuery.Columns("count(*) as count").From(r.tableName)
|
||||
countQuery = r.applyOptions(countQuery, options...)
|
||||
countQuery = r.applyFilters(countQuery, options...)
|
||||
query, args, err := r.toSql(countQuery)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user