Index the event-tier columns the sweeps, event log and retention scan (closes #314)
check / check (push) Successful in 3m4s
check / check (push) Successful in 3m4s
The per-webhook event databases had no secondary indexes, so startup recovery, the retry and pending sweeps, the queue-depth sampler, the event log and retention each read whole tables. Indexes declared in the GORM model tags now serve them, and AutoMigrate adds them to new and existing databases alike. Each index also covers deleted_at: GORM adds deleted_at IS NULL to these queries, and SQLite, with no table statistics, otherwise prefers the existing deleted_at index. A test checks SQLite's plan for each statement as GORM builds it. Rule suppressed: lll on the three event-tier model structs, whose struct tags cannot wrap. The resubmitted_from_id scan is left to #325. Model: opus-4-8 (implementation); opus-5-5 (rework)
This commit was merged in pull request #319.
This commit is contained in:
@@ -1,9 +1,27 @@
|
||||
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.
|
||||
CreatedAt time.Time `gorm:"index;index:idx_events_deleted_at_created_at,priority:2" json:"createdAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index:idx_events_deleted_at_created_at,priority:1" json:"deletedAt,omitzero"`
|
||||
|
||||
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
||||
EntrypointID string `gorm:"type:uuid;not null" json:"entrypointId"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user