feat(query-api): add richer stats and retention
This commit is contained in:
@@ -19,6 +19,7 @@ type EventsFilter struct {
|
||||
EventType string
|
||||
Framework string
|
||||
ClientID string
|
||||
Since *time.Time // if nil, defaults to 24h ago
|
||||
}
|
||||
|
||||
func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow, error) {
|
||||
@@ -29,10 +30,20 @@ func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow,
|
||||
f.Limit = 1000
|
||||
}
|
||||
|
||||
since := f.Since
|
||||
if since == nil {
|
||||
t := time.Now().Add(-24 * time.Hour)
|
||||
since = &t
|
||||
}
|
||||
|
||||
query := "SELECT event_id, ts, type, payload FROM events WHERE 1=1"
|
||||
args := []any{}
|
||||
argN := 1
|
||||
|
||||
query += fmt.Sprintf(" AND ts >= $%d", argN)
|
||||
args = append(args, *since)
|
||||
argN++
|
||||
|
||||
if f.EventType != "" {
|
||||
query += fmt.Sprintf(" AND type = $%d", argN)
|
||||
args = append(args, f.EventType)
|
||||
|
||||
Reference in New Issue
Block a user