graph

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

View Source
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

func Connect(ctx context.Context, url string) (*Client, error)

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) Clear

func (c *Client) Clear(ctx context.Context) error

Clear removes every node and relationship from the derived graph.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close releases the connection.

func (*Client) EnsureSchema added in v0.1.35

func (c *Client) EnsureSchema(ctx context.Context) error

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

func (c *Client) Ingest(ctx context.Context, km Killmail) error

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

func (c *Client) Purge(ctx context.Context, batchSize int) (PurgeResult, error)

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

type KilledEdge struct {
	AttackerID   int64
	VictimID     int64
	IskDestroyed float64
	FinalBlows   int64
}

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.

type PurgeResult

type PurgeResult struct {
	Edges     int64            `json:"edges"`
	Orphans   int64            `json:"orphans"`
	Killmails int64            `json:"killmails"`
	ByType    map[string]int64 `json:"by_type"`
}

PurgeResult reports what a prune removed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL