Documentation
¶
Overview ¶
Package maintenance holds the housekeeping jobs — the ones that are a SQL statement and a retention policy rather than an integration.
They are collected here rather than spread across the workers because they have nothing in common with the work they clean up after, and everything in common with each other: each is bounded, idempotent, and safe to run twice.
Index ¶
- Constants
- func Analyze(ctx context.Context, pool *pgxpool.Pool, tables []string) (int, error)
- func CompactPrices(ctx context.Context, pool *pgxpool.Pool) (int64, error)
- func PurgeFeed(ctx context.Context, pool *pgxpool.Pool) (int64, error)
- func ReconcileDailyCounts(ctx context.Context, pool *pgxpool.Pool, predicates map[string]string) (int64, error)
- func SnapshotEntities(ctx context.Context, pool *pgxpool.Pool) (int64, error)
- type EntityQueueResult
- type FittingsPurgeResult
- type StaleEntityOptions
Constants ¶
const ( DefaultEntityBatch = 500 DefaultEntityStaleDays = 30 )
const FittingsRetentionDays = 90
FittingsRetentionDays bounds the fittings tables to the window the item pages query over.
const MinDaysBeforeCompaction = 180
MinDaysBeforeCompaction guards against compacting a database that has barely any history. Without it, a fresh install with a week of prices would fold that week into a single point and lose it.
const PriceCompactionAfterDays = 90
PriceCompactionAfterDays is how much daily price history is kept before it is folded into weekly averages.
const ReconcileDays = 7
ReconcileDays is how far back the daily kill counts are rebuilt.
The rollup is bumped as each killmail is processed, and that bump logs and continues rather than failing the killmail — so drift is possible, rare, and worth correcting before it reaches a page anybody looks at. A week is far more than enough.
Variables ¶
This section is empty.
Functions ¶
func Analyze ¶
Analyze refreshes planner statistics on the tables large enough for autovacuum's proportional thresholds to leave stale.
On a table with hundreds of millions of rows autovacuum waits for tens of millions of changes before analysing, by which time the planner has been choosing badly for hours. Doing it on a schedule costs less than the sequential scans it prevents.
func CompactPrices ¶
CompactPrices folds daily price rows older than the retention window into weekly averages.
The weekly row is written at the Monday of its week, which is also a date the daily rows could occupy — so the delete afterwards deliberately spares any row already sitting on a week boundary. Deleting it would remove the aggregate that was just written.
func ReconcileDailyCounts ¶
func ReconcileDailyCounts(ctx context.Context, pool *pgxpool.Pool, predicates map[string]string) (int64, error)
ReconcileDailyCounts rebuilds the recent daily kill counts from the killmails themselves, correcting any drift in the incremental rollup.
func SnapshotEntities ¶
SnapshotEntities records today's member statistics per corporation and alliance.
Keyed by date and upserted, so running twice in a day overwrites rather than duplicating — which matters because the numbers move during the day and the last run of the day is the one worth keeping.
Types ¶
type EntityQueueResult ¶
type EntityQueueResult struct {
AllianceCandidates int64 `json:"alliance_candidates"`
AllianceQueued int64 `json:"alliance_queued"`
CorporationCandidates int64 `json:"corporation_candidates"`
CorporationQueued int64 `json:"corporation_queued"`
CharacterCandidates int64 `json:"character_candidates"`
CharacterQueued int64 `json:"character_queued"`
}
func QueueStaleEntities ¶
func QueueStaleEntities( ctx context.Context, pool *pgxpool.Pool, client *queue.Client, opts StaleEntityOptions, ) (EntityQueueResult, error)
QueueStaleEntities reproduces queue:stale-entities' three intentionally different repair sets:
- alliances and corporations are selected by updated_at age;
- NPC corporations are excluded;
- characters are selected only when birthday is missing or predates EVE.
Ordinary stale characters are refreshed by the live affiliation/entity cadence. Treating every stale character as a metadata repair turns this maintenance command into millions of unnecessary ESI requests.
type FittingsPurgeResult ¶
type FittingsPurgeResult struct {
Linkages int64 `json:"linkages"`
Fits int64 `json:"fits"`
Items int64 `json:"items"`
}
FittingsPurgeResult reports what each phase removed.
func PurgeFittings ¶
PurgeFittings trims the fittings tables.
The three phases must run in this order. Expiring the killmail linkages is what orphans a fit identity, and dropping the orphaned identity is what orphans its items — so running them out of order simply finds nothing to do and leaves the largest table untouched, which is where the space actually is.
Re-insertion is cheap, so there is no attempt to keep a fit around in case somebody flies it again. The retention window is the authoritative boundary.