check / check (push) Waiting to run
Several comments justified code by what an earlier build would have left in a database or on disk. Each now says what the code does: reserveSQLiteFile sets the mode on every open whoever created the file, and expired treats a session lacking a deadline's timestamp as expired. The comments on retention, resubmitted events, archive pruning, target headers, the redactor and the delivery result view drop their mentions of older rows. parseMaxRetries loses its paragraph on targets saved before the ceiling existed, and neither BeforeSave nor retentionCutoff cites a migration. Comments only. Model: opus-5-5
59 lines
2.8 KiB
Go
59 lines
2.8 KiB
Go
package database
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Event represents a captured webhook event
|
|
//
|
|
//nolint:lll // a struct tag cannot wrap
|
|
type Event struct {
|
|
BaseModel
|
|
|
|
// CreatedAt and DeletedAt repeat the BaseModel fields only to index
|
|
// them for retention, which finds events by age. Its lookups carry
|
|
// GORM's "deleted_at IS NULL" (see DeliveryResult) and compare
|
|
// created_at with <, so their index has deleted_at first: SQLite
|
|
// narrows by a < only on the last column it uses. Its final delete
|
|
// has no deleted_at condition and uses the index on created_at
|
|
// alone. The other tables keep the unindexed BaseModel created_at.
|
|
// DeletedAt is also the second column of the resubmitted_from_id
|
|
// index, for the reason DeliveryResult gives. The entrypoint_id
|
|
// index, for the webhook page's entrypoint list, has it second too,
|
|
// resubmitted_from_id third, and created_at last, which the list
|
|
// compares with a range.
|
|
CreatedAt time.Time `gorm:"index;index:idx_events_deleted_at_created_at,priority:2;index:idx_events_entrypoint_id,priority:4" json:"createdAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index:idx_events_deleted_at_created_at,priority:1;index:idx_events_resubmitted_from_id,priority:2;index:idx_events_entrypoint_id,priority:2" json:"deletedAt,omitzero"`
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
EntrypointID string `gorm:"type:uuid;not null;index:idx_events_entrypoint_id,priority:1" json:"entrypointId"`
|
|
|
|
// Request data. RawQuery is the receiving request's query string
|
|
// as sent, without the leading "?".
|
|
Method string `gorm:"not null" json:"method"`
|
|
RawQuery string `gorm:"type:text" json:"rawQuery"`
|
|
Headers string `gorm:"type:text" json:"headers"` // JSON
|
|
Body string `gorm:"type:text" json:"body"`
|
|
ContentType string `json:"contentType"`
|
|
|
|
// BodyBytes is the size of Body in bytes, recorded when the event
|
|
// is stored, so that the recent events list, which reads only the
|
|
// start of each body, knows the whole body's size.
|
|
BodyBytes int64 `gorm:"not null" json:"bodyBytes"`
|
|
|
|
// ResubmittedFromID names the event this one was copied from by
|
|
// an operator resubmit. It is nil for an event that arrived on
|
|
// the receiver. It is not a foreign key: the source event can be
|
|
// reaped by retention while its copies remain, and the id is
|
|
// kept as the record of where the copy came from either way.
|
|
ResubmittedFromID *string `gorm:"type:uuid;index:idx_events_resubmitted_from_id,priority:1;index:idx_events_entrypoint_id,priority:3" json:"resubmittedFromId,omitempty"`
|
|
|
|
// Relations. No model marshals the record it belongs to, so
|
|
// Webhook and Entrypoint are left out of the JSON.
|
|
Webhook Webhook `json:"-"`
|
|
Entrypoint Entrypoint `json:"-"`
|
|
Deliveries []Delivery `json:"deliveries,omitempty"`
|
|
}
|