From f8f5871411a4a455b0f00c49464ebddfc1cd5e06 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 7 Jun 2021 14:54:09 -0500 Subject: [PATCH] quick attempt to de-prioritize assets rules --- app/discovery/discovery.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/app/discovery/discovery.go b/app/discovery/discovery.go index 693ed7d..2607613 100644 --- a/app/discovery/discovery.go +++ b/app/discovery/discovery.go @@ -240,14 +240,14 @@ func (s *Service) Mappers() (mappers []URLMapper) { for _, m := range s.mappers { mappers = append(mappers, m...) } - sort.Slice(mappers, func(i, j int) bool { - // sort by len first, to make longer matches first - if len(mappers[i].SrcMatch.String()) != len(mappers[j].SrcMatch.String()) { - return len(mappers[i].SrcMatch.String()) > len(mappers[j].SrcMatch.String()) - } - // if len identical sort by SrcMatch string to keep same SrcMatch grouped together - return mappers[i].SrcMatch.String() < mappers[j].SrcMatch.String() - }) + // sort.Slice(mappers, func(i, j int) bool { + // // sort by len first, to make longer matches first + // if len(mappers[i].SrcMatch.String()) != len(mappers[j].SrcMatch.String()) { + // return len(mappers[i].SrcMatch.String()) > len(mappers[j].SrcMatch.String()) + // } + // // if len identical sort by SrcMatch string to keep same SrcMatch grouped together + // return mappers[i].SrcMatch.String() < mappers[j].SrcMatch.String() + // }) return mappers } @@ -322,6 +322,21 @@ func (s *Service) mergeLists() (res []URLMapper) { } res = append(res, lst...) } + + // sort rules to make assets last and prioritize longer rules first + sort.Slice(res, func(i, j int) bool { + // sort by len first, to make longer matches first + if len(res[i].SrcMatch.String()) != len(res[j].SrcMatch.String()) { + return len(res[i].SrcMatch.String()) > len(res[j].SrcMatch.String()) + } + // if len identical sort by SrcMatch string to keep same SrcMatch grouped together + return res[i].SrcMatch.String() < res[j].SrcMatch.String() + }) + + sort.Slice(res, func(i, j int) bool { + return res[i].MatchType < res[j].MatchType + }) + return res }