fix(inbounds): scale bulk client attachment selection (#7243)

With around 10,000 clients both attach dialogs loaded every client, pre-selected all of them and rendered every row, which locked the browser for minutes.

Both dialogs now ask the server for 100 rows at a time and render only the visible ones. Select All freezes the eligible client IDs that match the current search and group into a small server-issued token; the browser keeps that token plus the clients the operator unticked instead of thousands of emails, and the listing marks each row against the frozen filter so rows outside it stay unselected. On submit the server re-derives the same set and rejects the job before any write when its membership changed; clients created after the freeze stay outside it. The attach runs as a background job the dialog polls for counts.

Requests that post an email list keep their synchronous response. The Postgres job now runs the selection tests, which build their predicates by hand for both dialects.

Fixes #7236
This commit is contained in:
Hamed
2026-11-28 18:00:53 +03:30
committed by GitHub
parent 9088b8a768
commit 75dc6dc61c
34 changed files with 2643 additions and 492 deletions
+40
View File
@@ -452,6 +452,46 @@ export const EXAMPLES: Record<string, unknown> = {
"scope": "admin",
"token": "new-token-string"
},
"AttachCandidate": {
"alreadyAttached": false,
"comment": "Example client",
"email": "alice@example.test",
"enable": true,
"group": "staff",
"id": 1,
"inScope": true
},
"AttachCandidatePage": {
"eligible": 118,
"groups": [
"staff"
],
"items": [
{
"alreadyAttached": false,
"comment": "Example client",
"email": "alice@example.test",
"enable": true,
"group": "staff",
"id": 1,
"inScope": true
}
],
"maxId": 0,
"scopeToken": "",
"total": 120
},
"AttachJobStatus": {
"ended": "2025-01-01T00:00:00Z",
"error": "",
"result": null,
"running": false
},
"AttachSelectionResult": {
"attached": 9997,
"errors": 0,
"skipped": 0
},
"Blocker": {
"code": "tools",
"detail": "awg"
+134
View File
@@ -1877,6 +1877,140 @@ export const SCHEMAS: Record<string, unknown> = {
],
"type": "object"
},
"AttachCandidate": {
"properties": {
"alreadyAttached": {
"example": false,
"type": "boolean"
},
"comment": {
"example": "Example client",
"type": "string"
},
"email": {
"example": "alice@example.test",
"type": "string"
},
"enable": {
"example": true,
"type": "boolean"
},
"group": {
"example": "staff",
"type": "string"
},
"id": {
"example": 1,
"type": "integer"
},
"inScope": {
"example": true,
"type": "boolean"
}
},
"required": [
"alreadyAttached",
"comment",
"email",
"enable",
"group",
"id",
"inScope"
],
"type": "object"
},
"AttachCandidatePage": {
"properties": {
"eligible": {
"example": 118,
"format": "int64",
"type": "integer"
},
"groups": {
"example": [
"staff"
],
"items": {
"type": "string"
},
"type": "array"
},
"items": {
"items": {
"$ref": "#/components/schemas/AttachCandidate"
},
"type": "array"
},
"maxId": {
"type": "integer"
},
"scopeToken": {
"type": "string"
},
"total": {
"example": 120,
"format": "int64",
"type": "integer"
}
},
"required": [
"eligible",
"groups",
"items",
"total"
],
"type": "object"
},
"AttachJobStatus": {
"properties": {
"ended": {
"format": "date-time",
"type": "string"
},
"error": {
"type": "string"
},
"result": {
"allOf": [
{
"$ref": "#/components/schemas/AttachSelectionResult"
}
],
"nullable": true
},
"running": {
"example": false,
"type": "boolean"
}
},
"required": [
"ended",
"running"
],
"type": "object"
},
"AttachSelectionResult": {
"properties": {
"attached": {
"example": 9997,
"type": "integer"
},
"errors": {
"example": 0,
"type": "integer"
},
"skipped": {
"example": 0,
"type": "integer"
}
},
"required": [
"attached",
"errors",
"skipped"
],
"type": "object"
},
"Blocker": {
"description": "Blocker is one unmet requirement.",
"properties": {
+32
View File
@@ -447,6 +447,38 @@ export interface ApiTokenView {
token?: string;
}
export interface AttachCandidate {
alreadyAttached: boolean;
comment: string;
email: string;
enable: boolean;
group: string;
id: number;
inScope: boolean;
}
export interface AttachCandidatePage {
eligible: number;
groups: string[];
items: AttachCandidate[];
maxId?: number;
scopeToken?: string;
total: number;
}
export interface AttachJobStatus {
ended: string;
error?: string;
result?: AttachSelectionResult | null;
running: boolean;
}
export interface AttachSelectionResult {
attached: number;
errors: number;
skipped: number;
}
export interface Blocker {
code: BlockerCode;
detail?: string;
+36
View File
@@ -462,6 +462,42 @@ export const ApiTokenViewSchema = z.object({
});
export type ApiTokenView = z.infer<typeof ApiTokenViewSchema>;
export const AttachCandidateSchema = z.object({
alreadyAttached: z.boolean(),
comment: z.string(),
email: z.string(),
enable: z.boolean(),
group: z.string(),
id: z.number().int(),
inScope: z.boolean(),
});
export type AttachCandidate = z.infer<typeof AttachCandidateSchema>;
export const AttachCandidatePageSchema = z.object({
eligible: z.number().int(),
groups: z.array(z.string()),
items: z.array(z.lazy(() => AttachCandidateSchema)),
maxId: z.number().int().optional(),
scopeToken: z.string().optional(),
total: z.number().int(),
});
export type AttachCandidatePage = z.infer<typeof AttachCandidatePageSchema>;
export const AttachJobStatusSchema = z.object({
ended: z.string(),
error: z.string().optional(),
result: z.lazy(() => AttachSelectionResultSchema).nullable().optional(),
running: z.boolean(),
});
export type AttachJobStatus = z.infer<typeof AttachJobStatusSchema>;
export const AttachSelectionResultSchema = z.object({
attached: z.number().int(),
errors: z.number().int(),
skipped: z.number().int(),
});
export type AttachSelectionResult = z.infer<typeof AttachSelectionResultSchema>;
export const BlockerSchema = z.object({
code: z.lazy(() => BlockerCodeSchema),
detail: z.string().optional(),