Help us shape the future of Go! Take the 2026 Go Developer Survey

detect

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Query string
	Count int
}

Alert represents a detected N+1 query pattern.

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector tracks query frequency and detects N+1 patterns.

func New

func New(threshold int, window, cooldown time.Duration) *Detector

New creates a Detector. threshold: number of occurrences to trigger (e.g., 5). window: time window to count within (e.g., 1s). cooldown: minimum time between alerts for the same template (e.g., 10s).

func (*Detector) Record

func (d *Detector) Record(query string, t time.Time) Result

Record registers a query occurrence and returns a Result.

type Result

type Result struct {
	// Matched is true when the query count is at or above the threshold
	// within the time window. Use this to mark every event in the pattern.
	Matched bool
	// Alert is non-nil only when the threshold is first crossed (respecting
	// cooldown). Use this to trigger a one-time notification.
	Alert *Alert
}

Result holds the outcome of a Record call.

Jump to

Keyboard shortcuts

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