Performer disambiguation and aliases (#3113)

* Refactor performer relationships
* Remove checksum from performer
* Add disambiguation, overhaul aliases
* Add disambiguation filter criterion
* Improve name matching during import
* Add disambiguation filtering in UI
* Include aliases in performer select
This commit is contained in:
WithoutPants
2022-12-01 13:54:08 +11:00
committed by GitHub
parent d2395e579c
commit 4daf0a14a2
72 changed files with 2283 additions and 993 deletions

View File

@@ -42,6 +42,10 @@ type FileLoader interface {
GetFiles(ctx context.Context, relatedID int) ([]file.File, error)
}
type AliasLoader interface {
GetAliases(ctx context.Context, relatedID int) ([]string, error)
}
// RelatedIDs represents a list of related IDs.
// TODO - this can be made generic
type RelatedIDs struct {
@@ -481,3 +485,61 @@ func (r *RelatedFiles) loadPrimary(fn func() (file.File, error)) error {
return nil
}
// RelatedStrings represents a list of related strings.
// TODO - this can be made generic
type RelatedStrings struct {
list []string
}
// NewRelatedStrings returns a loaded RelatedStrings object with the provided values.
// Loaded will return true when called on the returned object if the provided slice is not nil.
func NewRelatedStrings(values []string) RelatedStrings {
return RelatedStrings{
list: values,
}
}
// Loaded returns true if the related IDs have been loaded.
func (r RelatedStrings) Loaded() bool {
return r.list != nil
}
func (r RelatedStrings) mustLoaded() {
if !r.Loaded() {
panic("list has not been loaded")
}
}
// List returns the related values. Panics if the relationship has not been loaded.
func (r RelatedStrings) List() []string {
r.mustLoaded()
return r.list
}
// Add adds the provided values to the list. Panics if the relationship has not been loaded.
func (r *RelatedStrings) Add(values ...string) {
r.mustLoaded()
r.list = append(r.list, values...)
}
func (r *RelatedStrings) load(fn func() ([]string, error)) error {
if r.Loaded() {
return nil
}
values, err := fn()
if err != nil {
return err
}
if values == nil {
values = []string{}
}
r.list = values
return nil
}