You've already forked caddy-opnsense-blocker
Adopt Tabulator for the requests log
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user