fix(intercept): avoid full-history polling and full-table counts

- Add partial covering index on intercept_pending(task_id, created_at DESC) INCLUDE (agent_name) WHERE status = 'pending'.
- Add GET /api/intercept/pending/summary (global count or per-task count + agent_names) and ?task_id= filtering on GET /api/intercept/pending.
- Cap unpaginated GET /api/intercept/task/{taskID} at 200 rows and remove unused tasks JOIN from non-search approval queries.
- Replace unbounded SELECT COUNT(*) in paginated approval queries with end-of-list shortcut, pg_class/pg_stat catalog estimate for large unfiltered tables, and bounded counting (10,000 cap) for large filtered sets.
- Deduplicate task detail and sessions-tab polling via single pending summary poll, switch sidebar badge to summary count, and guard approval polling against background tabs, overlapping requests, and deep-page/search churn.

Fixes #186
This commit is contained in:
ji ruo committed 2026-11-26 00:54:26 +08:00
1 parent 253a8eeac3
commit ea49ba0a3a
14 files changed
+676 -159

No files matched your search

+1
View File
@@ -1152,6 +1152,7 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("POST /api/asset-intercept/rules/{id}/toggle", s.assetInterceptToggleRule)
mux.HandleFunc("GET /api/intercept/pending", s.interceptListPending)
mux.HandleFunc("GET /api/intercept/pending/summary", s.interceptPendingSummary)
mux.HandleFunc("GET /api/intercept/pending/{id}", s.interceptGetOne)
mux.HandleFunc("POST /api/intercept/pending/{id}/decide", s.interceptDecide)
mux.HandleFunc("GET /api/intercept/history", s.interceptHistory)