mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
fix(filters): ensure sort by priority (#1325)
* fix(filters): sort filters from filtersMap * fix(filters): use slices.SortStableFunc and fix tests * fix(filters): add local cmp pkg before go 1.21
This commit is contained in:
parent
c060814022
commit
a0a81ed34c
3 changed files with 125 additions and 6 deletions
|
@ -12,11 +12,13 @@ import (
|
|||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/logger"
|
||||
"github.com/autobrr/autobrr/pkg/cmp"
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
"github.com/rs/zerolog"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type FilterRepo struct {
|
||||
|
@ -713,6 +715,12 @@ func (r *FilterRepo) findByIndexerIdentifier(ctx context.Context, indexer string
|
|||
filters = append(filters, filter)
|
||||
}
|
||||
|
||||
// the filterMap messes up the order, so we need to sort the filters slice
|
||||
slices.SortStableFunc(filters, func(a, b *domain.Filter) int {
|
||||
// TODO remove with Go 1.21 and use std lib cmp
|
||||
return cmp.Compare(b.Priority, a.Priority)
|
||||
})
|
||||
|
||||
return filters, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue