Skip to content

Commit

Permalink
Fix event.Manager category cache
Browse files Browse the repository at this point in the history
Since we don't use pointer receivers, the eventCategory map was being
initialized on a copy of the manager struct.  Initialize the map in the
constructor so we properly cache the one time fetch of event categories.
  • Loading branch information
dougm committed Sep 15, 2015
1 parent 7f0a892 commit f9deb38
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions event/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewManager(c *vim25.Client) *Manager {

c: c,

eventCategory: make(map[string]string),
eventCategoryMu: new(sync.Mutex),
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func (m Manager) eventCategoryMap(ctx context.Context) (map[string]string, error
m.eventCategoryMu.Lock()
defer m.eventCategoryMu.Unlock()

if m.eventCategory != nil {
if len(m.eventCategory) != 0 {
return m.eventCategory, nil
}

Expand All @@ -137,8 +138,6 @@ func (m Manager) eventCategoryMap(ctx context.Context) (map[string]string, error
return nil, err
}

m.eventCategory = make(map[string]string, len(o.Description.EventInfo))

for _, info := range o.Description.EventInfo {
m.eventCategory[info.Key] = info.Category
}
Expand Down

0 comments on commit f9deb38

Please sign in to comment.