From 0aa7b50985ed858b25d5d2bb0f23e0201730bd39 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Wed, 8 May 2024 12:28:23 +1000 Subject: [PATCH] Fix alias issue when tagging performer from stash-box --- pkg/scraper/stashbox/stash_box.go | 3 +++ pkg/sliceutil/stringslice/string_collections.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/scraper/stashbox/stash_box.go b/pkg/scraper/stashbox/stash_box.go index a793e1b08c0..c833d3d0ca7 100644 --- a/pkg/scraper/stashbox/stash_box.go +++ b/pkg/scraper/stashbox/stash_box.go @@ -676,6 +676,9 @@ func performerFragmentToScrapedPerformer(p graphql.PerformerFragment) *models.Sc return !strings.EqualFold(s, p.Name) }) + // #4596 - stash-box may return duplicate aliases. Filter these out + p.Aliases = stringslice.UniqueFold(p.Aliases) + alias := strings.Join(p.Aliases, ", ") sp.Aliases = &alias } diff --git a/pkg/sliceutil/stringslice/string_collections.go b/pkg/sliceutil/stringslice/string_collections.go index 051fe1d9ea7..e4b9ca6a915 100644 --- a/pkg/sliceutil/stringslice/string_collections.go +++ b/pkg/sliceutil/stringslice/string_collections.go @@ -29,3 +29,18 @@ func FromString(s string, sep string) []string { } return v } + +// Unique returns a slice containing only unique values from the provided slice. +// The comparison is case-insensitive. +func UniqueFold(s []string) []string { + seen := make(map[string]struct{}) + var ret []string + for _, v := range s { + if _, exists := seen[strings.ToLower(v)]; exists { + continue + } + seen[strings.ToLower(v)] = struct{}{} + ret = append(ret, v) + } + return ret +}