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) EnsureSchema(ctx context.Context) error
- func (c *Client) Ingest(ctx context.Context, km Killmail) (resultErr error)
- func (c *Client) Purge(ctx context.Context, batchSize int) (result PurgeResult, resultErr error)
- func (c *Client) Read(ctx context.Context, cypher string, params map[string]any) (records []map[string]any, resultErr 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) EnsureSchema ¶ added in v0.1.35
EnsureSchema installs uniqueness constraints for concurrency safety and explicit indexes for id lookups, affiliation and retention predicates. Memgraph's uniqueness constraints do not supply indexes to the query planner; omitting an id index makes MERGE scan the graph even when ids are unique. Equivalent schema creation is a no-op.
This is deliberately explicit rather than part of Connect: adding an index across a production graph is an operational change, and a uniqueness constraint must report pre-existing duplicate nodes without taking every graph-backed API offline.
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, ) (records []map[string]any, resultErr 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.