mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
convenience methods for node
This commit is contained in:
@@ -29,22 +29,25 @@ type Node struct {
|
|||||||
Records []Record
|
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.
|
// Record contains the timestamp of a node update.
|
||||||
type Record struct {
|
type Record struct {
|
||||||
Kind int // either [Addition], [Promotion] or [Demotion]
|
Kind int // either [Addition], [Promotion] or [Demotion]
|
||||||
Timestamp time.Time
|
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.
|
// 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).
|
// Add and Remove contain node IDs to add to or remove from the node’s relationships (e.g., follow list).
|
||||||
type Delta struct {
|
type Delta struct {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ func arbiterScan(ctx context.Context, config ArbiterConfig, db redb.RedisDB, sen
|
|||||||
|
|
||||||
case graph.StatusInactive:
|
case graph.StatusInactive:
|
||||||
// inactive --> active
|
// inactive --> active
|
||||||
added, found := node.Added()
|
added, found := node.Addition()
|
||||||
if !found {
|
if !found {
|
||||||
return promoted, demoted, fmt.Errorf("node %s doesn't have an addition record", node.ID)
|
return promoted, demoted, fmt.Errorf("node %s doesn't have an addition record", node.ID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user