mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Clear function to clear things on reparse
This commit is contained in:
@@ -27,9 +27,6 @@ func (r *Resolver[T]) Add(typeName, refID string, item Resolved[T]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver[T]) Get(typeName, refID string) ([]Resolved[T], error) {
|
func (r *Resolver[T]) Get(typeName, refID string) ([]Resolved[T], error) {
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
|
|
||||||
if typeIndex, exists := r.index[typeName]; exists {
|
if typeIndex, exists := r.index[typeName]; exists {
|
||||||
if items, ok := typeIndex[refID]; ok {
|
if items, ok := typeIndex[refID]; ok {
|
||||||
return items, nil
|
return items, nil
|
||||||
@@ -38,3 +35,10 @@ func (r *Resolver[T]) Get(typeName, refID string) ([]Resolved[T], error) {
|
|||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no index exists for type '%s'", typeName)
|
return nil, fmt.Errorf("no index exists for type '%s'", typeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resolver[T]) Clear() {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
|
r.index = make(map[string]map[string][]Resolved[T])
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INFO: All lookups are O(1)
|
|
||||||
for _, a := range res.Agents {
|
for _, a := range res.Agents {
|
||||||
if works, err := lib.Works.ReverseLookup(a); err == nil {
|
if works, err := lib.Works.ReverseLookup(a); err == nil {
|
||||||
for _, w := range works {
|
for _, w := range works {
|
||||||
if pieces, err := lib.Pieces.ReverseLookup(w.Item); err == nil {
|
if pieces, err := lib.Pieces.ReverseLookup(w.Item); err == nil {
|
||||||
|
// INFO: it makes no sense to append works that have no pieces attached
|
||||||
a.Works = append(a.Works, WorkByAgent{Resolved: w, Pieces: pieces})
|
a.Works = append(a.Works, WorkByAgent{Resolved: w, Pieces: pieces})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user