mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 05:01:50 +08:00
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:
1 parent
253a8eeac3
commit
ea49ba0a3a
14 files changed
+676
-159
No files matched your search
+40
-11
@@ -55,9 +55,11 @@ import type {
|
||||
IntelligencePage,
|
||||
IntentAsset,
|
||||
InterceptApprovalFilter,
|
||||
InterceptApprovalPage,
|
||||
InterceptApprovalRow,
|
||||
InterceptDetail,
|
||||
InterceptPending,
|
||||
InterceptPendingSummary,
|
||||
InterceptRule,
|
||||
JudgeConfig,
|
||||
JudgeUsage,
|
||||
@@ -1668,7 +1670,17 @@ export const api = {
|
||||
post<{ ok: boolean; enabled: boolean }>(`/asset-intercept/rules/${id}/toggle`, { enabled }),
|
||||
|
||||
// ---- intercept pending (ask) ----
|
||||
interceptPending: () => get<{ pending: InterceptPending[] }>("/intercept/pending").then((r) => arr(r.pending)),
|
||||
interceptPending: (taskId?: string) =>
|
||||
get<{ pending: InterceptPending[] }>(
|
||||
taskId ? `/intercept/pending?task_id=${encodeURIComponent(taskId)}` : "/intercept/pending",
|
||||
).then((r) => arr(r.pending)),
|
||||
interceptPendingSummary: (taskId?: string): Promise<InterceptPendingSummary> =>
|
||||
get<{ count?: number; agent_names?: string[] }>(
|
||||
taskId ? `/intercept/pending/summary?task_id=${encodeURIComponent(taskId)}` : "/intercept/pending/summary",
|
||||
).then((r) => ({
|
||||
count: r.count ?? 0,
|
||||
agent_names: arr(r.agent_names),
|
||||
})),
|
||||
interceptGetOne: (id: number) => get<InterceptPending>(`/intercept/pending/${id}`),
|
||||
interceptDecide: (id: number, decision: "allowed" | "denied") =>
|
||||
post<{ ok: boolean }>(`/intercept/pending/${id}/decide`, { decision }),
|
||||
@@ -1678,21 +1690,38 @@ export const api = {
|
||||
),
|
||||
interceptDetail: (id: number) => get<InterceptDetail>(`/intercept/history/${id}`),
|
||||
interceptHistory: () => get<{ items: InterceptApprovalRow[] }>("/intercept/history").then((r) => arr(r.items)),
|
||||
interceptHistoryPage: (page = 1, size = 20, filter: InterceptApprovalFilter = {}) =>
|
||||
get<{ items: InterceptApprovalRow[]; total?: number }>(
|
||||
`/intercept/history?${interceptPageQuery(page, size, filter)}`,
|
||||
).then((r) => ({
|
||||
interceptHistoryPage: (page = 1, size = 20, filter: InterceptApprovalFilter = {}): Promise<InterceptApprovalPage> =>
|
||||
get<{
|
||||
items: InterceptApprovalRow[];
|
||||
total?: number;
|
||||
total_approximate?: boolean;
|
||||
total_capped?: boolean;
|
||||
has_more?: boolean;
|
||||
}>(`/intercept/history?${interceptPageQuery(page, size, filter)}`).then((r) => ({
|
||||
items: arr(r.items),
|
||||
total: r.total ?? r.items?.length ?? 0,
|
||||
total_approximate: Boolean(r.total_approximate),
|
||||
total_capped: Boolean(r.total_capped),
|
||||
has_more: Boolean(r.has_more),
|
||||
})),
|
||||
interceptTask: (taskId: string) =>
|
||||
get<{ items: InterceptApprovalRow[] }>(`/intercept/task/${taskId}`).then((r) => arr(r.items)),
|
||||
interceptTaskPage: (taskId: string, page = 1, size = 20, filter: InterceptApprovalFilter = {}) =>
|
||||
get<{ items: InterceptApprovalRow[]; total?: number }>(
|
||||
`/intercept/task/${encodeURIComponent(taskId)}?${interceptPageQuery(page, size, filter)}`,
|
||||
).then((r) => ({
|
||||
interceptTaskPage: (
|
||||
taskId: string,
|
||||
page = 1,
|
||||
size = 20,
|
||||
filter: InterceptApprovalFilter = {},
|
||||
): Promise<InterceptApprovalPage> =>
|
||||
get<{
|
||||
items: InterceptApprovalRow[];
|
||||
total?: number;
|
||||
total_approximate?: boolean;
|
||||
total_capped?: boolean;
|
||||
has_more?: boolean;
|
||||
}>(`/intercept/task/${encodeURIComponent(taskId)}?${interceptPageQuery(page, size, filter)}`).then((r) => ({
|
||||
items: arr(r.items),
|
||||
total: r.total ?? r.items?.length ?? 0,
|
||||
total_approximate: Boolean(r.total_approximate),
|
||||
total_capped: Boolean(r.total_capped),
|
||||
has_more: Boolean(r.has_more),
|
||||
})),
|
||||
|
||||
// ---- intercept tool-config (全局工具拦截范围) ----
|
||||
|
||||
Reference in new issue
Block a user