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:
ze0s 2023-12-31 14:59:12 +01:00 committed by GitHub
parent c060814022
commit a0a81ed34c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 6 deletions

View file

@ -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
}