2

Adopt Tabulator for the requests log

This commit is contained in:
2026-03-12 21:01:34 +01:00
parent c213054f82
commit 9273c0ae69
10 changed files with 433 additions and 339 deletions

View File

@@ -987,6 +987,31 @@ func (s *Store) ListEvents(ctx context.Context, since time.Time, limit int, opti
return items, nil
}
func (s *Store) CountEvents(ctx context.Context, since time.Time, options model.EventListOptions) (int64, error) {
joins, clauses, filterArgs, err := eventFilterQueryParts(options)
if err != nil {
return 0, err
}
query := `SELECT COUNT(*) FROM events e`
if len(joins) > 0 {
query += ` ` + strings.Join(joins, ` `)
}
args := make([]any, 0, len(filterArgs)+1)
if !since.IsZero() {
clauses = append([]string{`e.occurred_at >= ?`}, clauses...)
args = append(args, formatTime(since))
}
args = append(args, filterArgs...)
if len(clauses) > 0 {
query += ` WHERE ` + strings.Join(clauses, ` AND `)
}
var total int64
if err := s.db.QueryRowContext(ctx, query, args...).Scan(&total); err != nil {
return 0, fmt.Errorf("count events: %w", err)
}
return total, nil
}
func (s *Store) ListRecentEvents(ctx context.Context, limit int) ([]model.Event, error) {
if limit <= 0 {
limit = 50