Documentation
¶
Overview ¶
Package graph maintains the relationship graph in Memgraph.
Postgres answers "what happened"; this answers "who flies with whom". Those are different shapes of question — the second is a traversal over an arbitrary number of hops, which relational joins do badly and a graph database does natively — which is why a second store exists at all.
Everything here is derived: the graph can be dropped and rebuilt from the killmails at any time. That is what makes the retention policy safe, and why a failure to write an edge is not worth failing a killmail over.
Index ¶
- Constants
- Variables
- type Character
- type Client
- func (c *Client) Clear(ctx context.Context) error
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Ingest(ctx context.Context, km Killmail) error
- func (c *Client) Purge(ctx context.Context, batchSize int) (PurgeResult, error)
- func (c *Client) Read(ctx context.Context, cypher string, params map[string]any) ([]map[string]any, error)
- type FlewWithEdge
- type KilledEdge
- type Killmail
- type PurgeResult
Constants ¶
const RetentionDays = 90
RetentionDays bounds how far back relationships are kept.
Ninety days: the graph answers questions about who is flying together now, and an edge from a year ago describes a fleet that no longer exists.
Variables ¶
var EdgeTypes = []string{"FLEW_WITH", "KILLED", "OPERATED_IN", "MEMBER_OF", "ALLIED_WITH"}
EdgeTypes are the relationships stored. Listed because the purge iterates them and a type missing from the list is never pruned.
Functions ¶
This section is empty.
Types ¶
type Character ¶
type Character struct {
ID int64
CorporationID int64
AllianceID int64
LastFCSeen time.Time
LastSuperKill time.Time
LastBlopsSeen time.Time
LastCapitalKill time.Time
LastLogisticsSeen time.Time
}
Character is one participant in a killmail, as the graph stores them.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a Memgraph connection.
func Connect ¶
Connect opens a Memgraph connection.
Memgraph speaks the Bolt protocol, so Neo4j's driver is the client — the two are wire-compatible for everything used here.
func (*Client) Ingest ¶
Ingest writes one killmail's relationships.
Every edge uses max-wins on last_seen rather than overwriting it. Killmails arrive out of order — the repair cron backfills days-old kills alongside the live feed — and an older one must not drag an edge's last_seen backwards.
func (*Client) Purge ¶
Purge removes relationships older than the retention window, and any character left with none.
Batched rather than done in one statement. A single DELETE over ninety days of edges is a transaction large enough to exhaust Memgraph's memory, and a partial prune is harmless — the next run continues where this one stopped.
func (*Client) Read ¶
func (c *Client) Read( ctx context.Context, cypher string, params map[string]any, ) ([]map[string]any, error)
Read runs one read-only Cypher query and returns each record as a map. Public API intelligence endpoints use this for relationship lookups while keeping the Neo4j/Memgraph driver out of the HTTP package.
type FlewWithEdge ¶
type FlewWithEdge struct {
Lo, Hi int64
}
FlewWithEdge is a pair who appeared on the same side of one kill.
Stored with the lower id first so the pair is one edge rather than two: a flew-with relationship is symmetric, and storing both directions would double every weight.
type KilledEdge ¶
KilledEdge is one attacker-victim relationship.
type Killmail ¶
type Killmail struct {
KillmailID int64
KillmailTime time.Time
SolarSystemID int64
Characters []Character
Killed []KilledEdge
FlewWith []FlewWithEdge
}
Killmail is what one ingest writes.