Clear function to clear things on reparse

This commit is contained in:
Simon Martens
2025-01-07 20:13:08 +01:00
parent f2fd9f9c0a
commit 6cfed94ff6
2 changed files with 8 additions and 4 deletions

View File

@@ -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) {
r.mu.Lock()
defer r.mu.Unlock()
if typeIndex, exists := r.index[typeName]; exists {
if items, ok := typeIndex[refID]; ok {
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)
}
func (r *Resolver[T]) Clear() {
r.mu.Lock()
defer r.mu.Unlock()
r.index = make(map[string]map[string][]Resolved[T])
}

View File

@@ -52,11 +52,11 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
}
}
// INFO: All lookups are O(1)
for _, a := range res.Agents {
if works, err := lib.Works.ReverseLookup(a); err == nil {
for _, w := range works {
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})
}
}