diff --git a/pkg/graph/graph.go b/pkg/graph/graph.go index e035865..7e7dadc 100644 --- a/pkg/graph/graph.go +++ b/pkg/graph/graph.go @@ -29,22 +29,25 @@ type Node struct { Records []Record } -// Added returns the time a node was added to the database. -func (n *Node) Added() (time.Time, bool) { - for _, rec := range n.Records { - if rec.Kind == Addition { - return rec.Timestamp, true - } - } - return time.Time{}, false -} - // Record contains the timestamp of a node update. type Record struct { Kind int // either [Addition], [Promotion] or [Demotion] Timestamp time.Time } +func (n *Node) Addition() (time.Time, bool) { return n.find(Addition) } +func (n *Node) Promotion() (time.Time, bool) { return n.find(Promotion) } +func (n *Node) Demotion() (time.Time, bool) { return n.find(Demotion) } + +func (n *Node) find(kind int) (time.Time, bool) { + for _, record := range n.Records { + if record.Kind == kind { + return record.Timestamp, true + } + } + return time.Time{}, false +} + // Delta represents updates to apply to a Node. // Add and Remove contain node IDs to add to or remove from the node’s relationships (e.g., follow list). type Delta struct { diff --git a/pkg/pipe/engine.go b/pkg/pipe/engine.go index 11b3f20..5a64faa 100644 --- a/pkg/pipe/engine.go +++ b/pkg/pipe/engine.go @@ -135,7 +135,7 @@ func arbiterScan(ctx context.Context, config ArbiterConfig, db redb.RedisDB, sen case graph.StatusInactive: // inactive --> active - added, found := node.Added() + added, found := node.Addition() if !found { return promoted, demoted, fmt.Errorf("node %s doesn't have an addition record", node.ID) }