feat: page long and truncated lists
Lists that were cut off by a fixed LIMIT, or could grow without bound, are paged by keyset: the cursor holds the sort key and an ID, so pages neither skip nor repeat items as others are added. The audit logs had a timestamp-only cursor that could skip entries with equal times. The API returns at most 100 items per list (limit takes up to 500) with next_cursor and prev_cursor, passed back as after and before. The console shows Newer/Older (or Previous/Next) links and To the start, without JavaScript. Paged: incidents (optionally of one monitor), a monitor's results and evidence, a checker's results, the audit logs, members, maintenance windows, firing Alertmanager alerts, the monitors API and the admin lists of status pages and organizations, which move to their own admin pages. A monitor's page shows its latest incidents and results and links to all of them. The dashboard caps every group at 50 of its own monitors with a link to a paged view of the group, and gains a search by name or target. Lists filtered by permission after reading may show fewer items on a page. Closes #116 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
98fb5d3a82
commit
d7c5cd711e
63 files changed
+5427
-3041
No files matched your search
@@ -245,10 +245,25 @@ const listIncidents = `-- name: ListIncidents :many
|
||||
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, m.name AS monitor_name
|
||||
FROM incidents i
|
||||
JOIN monitors m ON m.id = i.monitor_id
|
||||
ORDER BY i.started_at DESC
|
||||
LIMIT 200
|
||||
WHERE ($1::uuid IS NULL OR i.monitor_id = $1)
|
||||
AND ($2::timestamptz IS NULL OR (i.started_at, i.id) < ($2, $3::uuid))
|
||||
AND ($4::timestamptz IS NULL OR (i.started_at, i.id) > ($4, $5::uuid))
|
||||
ORDER BY
|
||||
CASE WHEN $4::timestamptz IS NULL THEN i.started_at END DESC,
|
||||
CASE WHEN $4::timestamptz IS NULL THEN i.id END DESC,
|
||||
i.started_at, i.id
|
||||
LIMIT $6
|
||||
`
|
||||
|
||||
type ListIncidentsParams struct {
|
||||
MonitorID *uuid.UUID
|
||||
AfterT *time.Time
|
||||
AfterID *uuid.UUID
|
||||
BeforeT *time.Time
|
||||
BeforeID *uuid.UUID
|
||||
MaxRows int32
|
||||
}
|
||||
|
||||
type ListIncidentsRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
@@ -259,8 +274,17 @@ type ListIncidentsRow struct {
|
||||
MonitorName string
|
||||
}
|
||||
|
||||
func (q *Queries) ListIncidents(ctx context.Context) ([]ListIncidentsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listIncidents)
|
||||
// Newest first, a page from a keyset cursor (see paging.go); optionally of
|
||||
// one monitor.
|
||||
func (q *Queries) ListIncidents(ctx context.Context, arg ListIncidentsParams) ([]ListIncidentsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listIncidents,
|
||||
arg.MonitorID,
|
||||
arg.AfterT,
|
||||
arg.AfterID,
|
||||
arg.BeforeT,
|
||||
arg.BeforeID,
|
||||
arg.MaxRows,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -321,37 +345,6 @@ func (q *Queries) MarkNotificationSent(ctx context.Context, id uuid.UUID) error
|
||||
return err
|
||||
}
|
||||
|
||||
const monitorIncidents = `-- name: MonitorIncidents :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20
|
||||
`
|
||||
|
||||
func (q *Queries) MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error) {
|
||||
rows, err := q.db.Query(ctx, monitorIncidents, monitorID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Incident{}
|
||||
for rows.Next() {
|
||||
var i Incident
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.MonitorID,
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const notificationDetails = `-- name: NotificationDetails :many
|
||||
SELECT n.id, n.org_id, n.event, n.attempts,
|
||||
c.type AS channel_type, c.config AS channel_config, c.id AS channel_id,
|
||||
|
||||
Reference in new issue
Block a user