🐛 Deduplicate recipes
This commit is contained in:
parent
d55c680ec4
commit
24436ce28b
1 changed files with 24 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
_ "github.com/glebarez/go-sqlite"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
|
@ -196,13 +197,35 @@ func (m *Merger) getRecipes(ctx context.Context, items []Item) (err error) {
|
|||
if recs, found = rm[items[idx].Id]; found {
|
||||
items[idx].Recipes = make([][]int32, 0, len(recs))
|
||||
for _, rec := range recs {
|
||||
items[idx].Recipes = append(items[idx].Recipes, rec)
|
||||
addRecs(&(items[idx].Recipes), rec)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addRecs(recs *[][]int32, rec []int32) {
|
||||
slices.Sort(rec)
|
||||
if !slices.ContainsFunc(*recs, recSorter(rec)) {
|
||||
*recs = append(*recs, rec)
|
||||
}
|
||||
}
|
||||
|
||||
func recSorter(rec []int32) func([]int32) bool {
|
||||
return func(v []int32) bool {
|
||||
slices.Sort(v)
|
||||
if !(len(v) == len(rec)) {
|
||||
return false
|
||||
}
|
||||
for idx, i := range v {
|
||||
if !(i == rec[idx]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Merger) Merge(ctx context.Context) (g Game, err error) {
|
||||
if err = m.getGameDetails(ctx, &g); err != nil {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue