check / check (push) Failing after 2s
The per-webhook tables declared no secondary indexes, so the recovery and sweep queries (by delivery status, every minute), the event log (deliveries by event, results by delivery) and retention (events by age) each scanned a whole table. Add indexes through GORM model tags so AutoMigrate creates them on a fresh and on an existing per-webhook database. events.created_at is indexed by overriding the embedded BaseModel field on Event alone, leaving the other tables' created_at unindexed. A test drops the indexes from an opened database, reopens it, and asserts the open recreated them. The README Data Model section lists the indexes. Model: opus-4-8
37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package database
|
|
|
|
import "time"
|
|
|
|
// Event represents a captured webhook event
|
|
type Event struct {
|
|
BaseModel
|
|
|
|
// CreatedAt overrides BaseModel.CreatedAt only to add an index:
|
|
// retention deletes events by age, so events.created_at is queried
|
|
// on every sweep. The other tables keep the unindexed BaseModel
|
|
// field.
|
|
CreatedAt time.Time `gorm:"index" json:"createdAt"`
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
EntrypointID string `gorm:"type:uuid;not null" json:"entrypointId"`
|
|
|
|
// Request data
|
|
Method string `gorm:"not null" json:"method"`
|
|
Headers string `gorm:"type:text" json:"headers"` // JSON
|
|
Body string `gorm:"type:text" json:"body"`
|
|
ContentType string `json:"contentType"`
|
|
|
|
// ResubmittedFromID names the event this one was copied from by
|
|
// an operator resubmit. It is nil for an event that arrived on
|
|
// the receiver, which is every event created before the column
|
|
// existed. 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" json:"resubmittedFromId,omitempty"`
|
|
|
|
// Relations
|
|
Webhook Webhook `json:"webhook,omitzero"`
|
|
Entrypoint Entrypoint `json:"entrypoint,omitzero"`
|
|
Deliveries []Delivery `json:"deliveries,omitempty"`
|
|
}
|