Add missing read lock in getNodes

This commit is contained in:
Bjørn Erik Pedersen 2016-09-08 16:51:32 +03:00
parent a8fad86671
commit 97c57fe37a
2 changed files with 5 additions and 4 deletions

View file

@ -42,7 +42,7 @@ type HugoSites struct {
// Maps internalID to a set of nodes.
nodeMap map[string]Nodes
nodeMapMu sync.Mutex
nodeMapMu sync.RWMutex
}
// NewHugoSites creates a new collection of sites given the input sites, building
@ -108,9 +108,11 @@ func (h *HugoSites) addNode(nodeID string, node *Node) {
}
func (h *HugoSites) getNodes(nodeID string) Nodes {
// At this point it is read only, so no need to lock.
if nodeID != "" {
if nodes, ok := h.nodeMap[nodeID]; ok {
h.nodeMapMu.RLock()
nodes, ok := h.nodeMap[nodeID]
h.nodeMapMu.RUnlock()
if ok {
return nodes
}
}

View file

@ -288,7 +288,6 @@ func (n *Node) IsTranslated() bool {
func (n *Node) initTranslations() {
n.translationsInit.Do(func() {
n.translations = n.Site.owner.getNodes(n.nodeID)
//sort.Sort(n.translations)
})
}