feat(webui): page and filter the task list on the server

This commit is contained in:
sam committed 2026-10-05 20:21:51 +11:00
1 parent 21ab0adaec
commit bdf4fa9730
15 files changed
+550 -384

No files matched your search

@@ -8,6 +8,8 @@ package postgresdb
import (
"context"
"time"
"github.com/jackc/pgx/v5/pgtype"
)
const appendPendingReview = `-- name: AppendPendingReview :execrows
@@ -480,9 +482,21 @@ SELECT id, owner, repo, issue_number, title, status, workflow,
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
created_at, updated_at, plan, source, identity, binding_id, binding_version,
outputs, review_gate, rereview_rounds
FROM tasks ORDER BY updated_at DESC LIMIT $1
FROM tasks
WHERE (cardinality($1::text[]) = 0 OR status = ANY($1::text[]))
AND ($2::timestamptz IS NULL
OR (updated_at, id) < ($2::timestamptz, $3::bigint))
ORDER BY updated_at DESC, id DESC
LIMIT $4
`
type ListTaskSummariesParams struct {
Statuses []string
BeforeUpdated pgtype.Timestamptz
BeforeID int64
PageLimit int32
}
type ListTaskSummariesRow struct {
ID int64
Owner string
@@ -518,8 +532,13 @@ type ListTaskSummariesRow struct {
// wrote is what the operator reads before answering it
// (docs/prds/pr-review-operator-response.md, "The review the operator
// answers"), and the round count is the cap's visible half.
func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTaskSummariesRow, error) {
rows, err := q.db.Query(ctx, listTaskSummaries, limit)
func (q *Queries) ListTaskSummaries(ctx context.Context, arg ListTaskSummariesParams) ([]ListTaskSummariesRow, error) {
rows, err := q.db.Query(ctx, listTaskSummaries,
arg.Statuses,
arg.BeforeUpdated,
arg.BeforeID,
arg.PageLimit,
)
if err != nil {
return nil, err
}
@@ -42,7 +42,12 @@ SELECT id, owner, repo, issue_number, title, status, workflow,
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
created_at, updated_at, plan, source, identity, binding_id, binding_version,
outputs, review_gate, rereview_rounds
FROM tasks ORDER BY updated_at DESC LIMIT $1;
FROM tasks
WHERE (cardinality(@statuses::text[]) = 0 OR status = ANY(@statuses::text[]))
AND (sqlc.narg(before_updated)::timestamptz IS NULL
OR (updated_at, id) < (sqlc.narg(before_updated)::timestamptz, @before_id::bigint))
ORDER BY updated_at DESC, id DESC
LIMIT @page_limit;
-- name: CountTasksByStatus :many
SELECT status, count(*)::int AS count FROM tasks GROUP BY status;
+16 -2
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samcharles93/archie-core/internal/domain/org"
@@ -627,9 +628,22 @@ func (s *Store) ClearTerminalTasks(ctx context.Context) (int64, error) {
return s.queries().ClearTerminalTasks(ctx)
}
// Tasks returns all tasks, newest first (dashboard listing).
// Tasks returns the most recently updated tasks.
func (s *Store) Tasks(ctx context.Context, limit int) ([]workflow.Task, error) {
rows, err := s.queries().ListTaskSummaries(ctx, int32(limit))
return s.TasksPage(ctx, storecontract.TaskPage{Limit: limit})
}
// TasksPage returns one page of tasks, most recently updated first.
func (s *Store) TasksPage(ctx context.Context, page storecontract.TaskPage) ([]workflow.Task, error) {
params := postgresdb.ListTaskSummariesParams{
Statuses: append([]string{}, page.Statuses...),
PageLimit: int32(min(max(page.Limit, 1), 500)), //nolint:gosec // clamped
}
if page.After.ID != 0 {
params.BeforeUpdated = pgtype.Timestamptz{Time: page.After.UpdatedAt, Valid: true}
params.BeforeID = page.After.ID
}
rows, err := s.queries().ListTaskSummaries(ctx, params)
if err != nil {
return nil, err
}