January 2020
Intermediate to advanced
640 pages
16h 56m
English
The last bit of functionality that we need to explore is the RemoveStaleEdges method. The caller invokes it with the ID of a link (the origin) and an updatedBefore value:
func (s *InMemoryGraph) RemoveStaleEdges(fromID uuid.UUID, updatedBefore time.Time) error { s.mu.Lock() defer s.mu.Unlock() var newEdgeList edgeList for _, edgeID := range s.linkEdgeMap[fromID] { edge := s.edges[edgeID] if edge.UpdatedAt.Before(updatedBefore) { delete(s.edges, edgeID) continue } newEdgeList = append(newEdgeList, edgeID) } s.linkEdgeMap[fromID] = newEdgeList return nil }
As with other operations that mutate the graph's contents, we need to acquire a write lock. Then, we iterate the list of edges that originate from the specified source ...