Avoid repeated glossary selection and membership work
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user