Avoid repeated glossary selection and membership work

This commit is contained in:
2026-11-10 20:39:00 +00:00
parent 1fd95abe95
commit 8ad27e8368
6 changed files with 39 additions and 22 deletions

View File

@@ -18,9 +18,14 @@ type identity struct{ collection, id string }
// Select retains the first occurrence of each selected collection entry.
func Select(collections map[string]config.GlossaryCollection, names []string) []Entry {
visited := make(map[string]struct{})
seen := make(map[identity]struct{})
var selected []Entry
for _, name := range names {
if _, exists := visited[name]; exists {
continue
}
visited[name] = struct{}{}
for _, item := range collections[name].Entries {
key := identity{collection: name, id: item.ID}
if _, exists := seen[key]; exists {