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
+43 -8
View File
@@ -13,6 +13,13 @@ _openapi:
reverse field, if set, is returned as a nested JSON object (legacy
JSON-encoded-string form is still accepted on write).
url: '#list-every-client-with-its-attached-inbound-ids-and-traffic-record-the-reverse-field-if-set-is-returned-as-a-nested-json-object-legacy-json-encoded-string-form-is-still-accepted-on-write'
- depth: 2
title: List up to 100 clients for the inbound attachment picker. Counts
distinguish filtered rows and all eligible clients. A freeze request
returns only the eligible count, maximum ID and a scope token covering
the eligible IDs that match the given search and group for the chosen
source and targets.
url: '#list-up-to-100-clients-for-the-inbound-attachment-picker-counts-distinguish-filtered-rows-and-all-eligible-clients-a-freeze-request-returns-only-the-eligible-count-maximum-id-and-a-scope-token-covering-the-eligible-ids-that-match-the-given-search-and-group-for-the-chosen-source-and-targets'
- depth: 2
title: 'Filter, sort, and paginate clients on the server. Each item is a slim
row (no uuid/password/auth/flow/security/reverse/tgId) so the clients
@@ -206,9 +213,21 @@ _openapi:
keeps its identity (email/UUID/password/subId) and a shared traffic row;
all clients are added to a target inbound in a single AddInboundClient
call. Clients already present on a target are reported under skipped.
Returns per-email attached/skipped/errors lists and triggers a single
Xray restart if any target inbound was running.
url: '#attach-many-existing-clients-to-many-inbounds-in-one-call-each-client-keeps-its-identity-emailuuidpasswordsubid-and-a-shared-traffic-row-all-clients-are-added-to-a-target-inbound-in-a-single-addinboundclient-call-clients-already-present-on-a-target-are-reported-under-skipped-returns-per-email-attachedskippederrors-lists-and-triggers-a-single-xray-restart-if-any-target-inbound-was-running'
Explicit email requests return per-email lists. Alternatively submit
selection with explicit clientIds or a frozen allMatching scopeToken
plus excludedClientIds and the search and group it was frozen under.
Scoped requests start a background job and return {jobId}. Poll GET
/bulkAttach/:id for counts or a stale-selection error. Newer IDs stay
outside the frozen scope. Changes to the frozen membership are rejected
before applying changes. Triggers a single Xray restart if any target
inbound was running.
url: '#attach-many-existing-clients-to-many-inbounds-in-one-call-each-client-keeps-its-identity-emailuuidpasswordsubid-and-a-shared-traffic-row-all-clients-are-added-to-a-target-inbound-in-a-single-addinboundclient-call-clients-already-present-on-a-target-are-reported-under-skipped-explicit-email-requests-return-per-email-lists-alternatively-submit-selection-with-explicit-clientids-or-a-frozen-allmatching-scopetoken-plus-excludedclientids-and-the-search-and-group-it-was-frozen-under-scoped-requests-start-a-background-job-and-return-jobid-poll-get-bulkattachid-for-counts-or-a-stale-selection-error-newer-ids-stay-outside-the-frozen-scope-changes-to-the-frozen-membership-are-rejected-before-applying-changes-triggers-a-single-xray-restart-if-any-target-inbound-was-running'
- depth: 2
title: Poll a scoped attachment job. The result contains counts per target
(attached, skipped, errors); an operation failure sets error instead.
Completed results are retained for up to 15 minutes in the running panel
process.
url: '#poll-a-scoped-attachment-job-the-result-contains-counts-per-target-attached-skipped-errors-an-operation-failure-sets-error-instead-completed-results-are-retained-for-up-to-15-minutes-in-the-running-panel-process'
- depth: 2
title: "Mirror of bulkAttach: detach many existing clients from many inbounds in
one call. For each email, intersects the client's current inbounds with
@@ -386,6 +405,12 @@ _openapi:
reverse field, if set, is returned as a nested JSON object (legacy
JSON-encoded-string form is still accepted on write).
id: list-every-client-with-its-attached-inbound-ids-and-traffic-record-the-reverse-field-if-set-is-returned-as-a-nested-json-object-legacy-json-encoded-string-form-is-still-accepted-on-write
- content: List up to 100 clients for the inbound attachment picker. Counts
distinguish filtered rows and all eligible clients. A freeze request
returns only the eligible count, maximum ID and a scope token covering
the eligible IDs that match the given search and group for the chosen
source and targets.
id: list-up-to-100-clients-for-the-inbound-attachment-picker-counts-distinguish-filtered-rows-and-all-eligible-clients-a-freeze-request-returns-only-the-eligible-count-maximum-id-and-a-scope-token-covering-the-eligible-ids-that-match-the-given-search-and-group-for-the-chosen-source-and-targets
- content: 'Filter, sort, and paginate clients on the server. Each item is a slim
row (no uuid/password/auth/flow/security/reverse/tgId) so the clients
page can ship 25-ish rows in a few KB instead of the full table. The
@@ -551,10 +576,20 @@ _openapi:
keeps its identity (email/UUID/password/subId) and a shared traffic
row; all clients are added to a target inbound in a single
AddInboundClient call. Clients already present on a target are
reported under skipped. Returns per-email attached/skipped/errors
lists and triggers a single Xray restart if any target inbound was
running.
id: attach-many-existing-clients-to-many-inbounds-in-one-call-each-client-keeps-its-identity-emailuuidpasswordsubid-and-a-shared-traffic-row-all-clients-are-added-to-a-target-inbound-in-a-single-addinboundclient-call-clients-already-present-on-a-target-are-reported-under-skipped-returns-per-email-attachedskippederrors-lists-and-triggers-a-single-xray-restart-if-any-target-inbound-was-running
reported under skipped. Explicit email requests return per-email
lists. Alternatively submit selection with explicit clientIds or a
frozen allMatching scopeToken plus excludedClientIds and the search
and group it was frozen under. Scoped requests start a background job
and return {jobId}. Poll GET /bulkAttach/:id for counts or a
stale-selection error. Newer IDs stay outside the frozen scope.
Changes to the frozen membership are rejected before applying changes.
Triggers a single Xray restart if any target inbound was running.
id: attach-many-existing-clients-to-many-inbounds-in-one-call-each-client-keeps-its-identity-emailuuidpasswordsubid-and-a-shared-traffic-row-all-clients-are-added-to-a-target-inbound-in-a-single-addinboundclient-call-clients-already-present-on-a-target-are-reported-under-skipped-explicit-email-requests-return-per-email-lists-alternatively-submit-selection-with-explicit-clientids-or-a-frozen-allmatching-scopetoken-plus-excludedclientids-and-the-search-and-group-it-was-frozen-under-scoped-requests-start-a-background-job-and-return-jobid-poll-get-bulkattachid-for-counts-or-a-stale-selection-error-newer-ids-stay-outside-the-frozen-scope-changes-to-the-frozen-membership-are-rejected-before-applying-changes-triggers-a-single-xray-restart-if-any-target-inbound-was-running
- content: Poll a scoped attachment job. The result contains counts per target
(attached, skipped, errors); an operation failure sets error instead.
Completed results are retained for up to 15 minutes in the running
panel process.
id: poll-a-scoped-attachment-job-the-result-contains-counts-per-target-attached-skipped-errors-an-operation-failure-sets-error-instead-completed-results-are-retained-for-up-to-15-minutes-in-the-running-panel-process
- content: "Mirror of bulkAttach: detach many existing clients from many inbounds
in one call. For each email, intersects the client's current inbounds
with the requested set and detaches from those only; (email, inbound)
@@ -883,7 +918,7 @@ export default function Layout(props) {
return (
<>
{props.children}
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/clients/list","method":"get"},{"path":"/panel/api/clients/list/paged","method":"get"},{"path":"/panel/api/clients/get/{email}","method":"get"},{"path":"/panel/api/clients/get","method":"get"},{"path":"/panel/api/clients/get/subId/{subId}","method":"get"},{"path":"/panel/api/clients/get/tgId/{tgId}","method":"get"},{"path":"/panel/api/clients/add","method":"post"},{"path":"/panel/api/clients/renewalPreview","method":"post"},{"path":"/panel/api/clients/update/{email}","method":"post"},{"path":"/panel/api/clients/update","method":"post"},{"path":"/panel/api/clients/del/{email}","method":"post"},{"path":"/panel/api/clients/del","method":"post"},{"path":"/panel/api/clients/{email}/attach","method":"post"},{"path":"/panel/api/clients/{email}/detach","method":"post"},{"path":"/panel/api/clients/{email}/externalLinks","method":"post"},{"path":"/panel/api/clients/wireguardDevices","method":"get"},{"path":"/panel/api/clients/wireguardDevices","method":"post"},{"path":"/panel/api/clients/wireguardDevices/limit","method":"put"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"patch"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"delete"},{"path":"/panel/api/clients/resetAllTraffics","method":"post"},{"path":"/panel/api/clients/delDepleted","method":"post"},{"path":"/panel/api/clients/delOrphans","method":"post"},{"path":"/panel/api/clients/export","method":"get"},{"path":"/panel/api/clients/import","method":"post"},{"path":"/panel/api/clients/bulkAdjust","method":"post"},{"path":"/panel/api/clients/bulkEnable","method":"post"},{"path":"/panel/api/clients/bulkDisable","method":"post"},{"path":"/panel/api/clients/bulkDel","method":"post"},{"path":"/panel/api/clients/bulkCreate","method":"post"},{"path":"/panel/api/clients/groups/bulkAdd","method":"post"},{"path":"/panel/api/clients/groups/bulkRemove","method":"post"},{"path":"/panel/api/clients/bulkAttach","method":"post"},{"path":"/panel/api/clients/bulkDetach","method":"post"},{"path":"/panel/api/clients/bulkResetTraffic","method":"post"},{"path":"/panel/api/clients/groups","method":"get"},{"path":"/panel/api/clients/groups/{name}/hosts","method":"post"},{"path":"/panel/api/clients/groups/{name}/emails","method":"get"},{"path":"/panel/api/clients/groups/create","method":"post"},{"path":"/panel/api/clients/groups/rename","method":"post"},{"path":"/panel/api/clients/groups/delete","method":"post"},{"path":"/panel/api/clients/groups/resetTraffic","method":"post"},{"path":"/panel/api/clients/resetTraffic/{email}","method":"post"},{"path":"/panel/api/clients/updateTraffic/{email}","method":"post"},{"path":"/panel/api/clients/ips/{email}","method":"post"},{"path":"/panel/api/clients/clearIps/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}/block","method":"post"},{"path":"/panel/api/clients/onlines","method":"post"},{"path":"/panel/api/clients/onlinesByGuid","method":"post"},{"path":"/panel/api/clients/clientIpsByGuid","method":"post"},{"path":"/panel/api/clients/activeInbounds","method":"post"},{"path":"/panel/api/clients/lastOnline","method":"post"},{"path":"/panel/api/clients/traffic/{email}","method":"get"},{"path":"/panel/api/clients/usageHistory/{email}","method":"get"},{"path":"/panel/api/clients/subLinks/{subId}","method":"get"},{"path":"/panel/api/clients/happLink/{id}","method":"post"},{"path":"/panel/api/clients/links/{email}","method":"get"}]} showTitle />
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/clients/list","method":"get"},{"path":"/panel/api/clients/attachCandidates","method":"get"},{"path":"/panel/api/clients/list/paged","method":"get"},{"path":"/panel/api/clients/get/{email}","method":"get"},{"path":"/panel/api/clients/get","method":"get"},{"path":"/panel/api/clients/get/subId/{subId}","method":"get"},{"path":"/panel/api/clients/get/tgId/{tgId}","method":"get"},{"path":"/panel/api/clients/add","method":"post"},{"path":"/panel/api/clients/renewalPreview","method":"post"},{"path":"/panel/api/clients/update/{email}","method":"post"},{"path":"/panel/api/clients/update","method":"post"},{"path":"/panel/api/clients/del/{email}","method":"post"},{"path":"/panel/api/clients/del","method":"post"},{"path":"/panel/api/clients/{email}/attach","method":"post"},{"path":"/panel/api/clients/{email}/detach","method":"post"},{"path":"/panel/api/clients/{email}/externalLinks","method":"post"},{"path":"/panel/api/clients/wireguardDevices","method":"get"},{"path":"/panel/api/clients/wireguardDevices","method":"post"},{"path":"/panel/api/clients/wireguardDevices/limit","method":"put"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"patch"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"delete"},{"path":"/panel/api/clients/resetAllTraffics","method":"post"},{"path":"/panel/api/clients/delDepleted","method":"post"},{"path":"/panel/api/clients/delOrphans","method":"post"},{"path":"/panel/api/clients/export","method":"get"},{"path":"/panel/api/clients/import","method":"post"},{"path":"/panel/api/clients/bulkAdjust","method":"post"},{"path":"/panel/api/clients/bulkEnable","method":"post"},{"path":"/panel/api/clients/bulkDisable","method":"post"},{"path":"/panel/api/clients/bulkDel","method":"post"},{"path":"/panel/api/clients/bulkCreate","method":"post"},{"path":"/panel/api/clients/groups/bulkAdd","method":"post"},{"path":"/panel/api/clients/groups/bulkRemove","method":"post"},{"path":"/panel/api/clients/bulkAttach","method":"post"},{"path":"/panel/api/clients/bulkAttach/{id}","method":"get"},{"path":"/panel/api/clients/bulkDetach","method":"post"},{"path":"/panel/api/clients/bulkResetTraffic","method":"post"},{"path":"/panel/api/clients/groups","method":"get"},{"path":"/panel/api/clients/groups/{name}/hosts","method":"post"},{"path":"/panel/api/clients/groups/{name}/emails","method":"get"},{"path":"/panel/api/clients/groups/create","method":"post"},{"path":"/panel/api/clients/groups/rename","method":"post"},{"path":"/panel/api/clients/groups/delete","method":"post"},{"path":"/panel/api/clients/groups/resetTraffic","method":"post"},{"path":"/panel/api/clients/resetTraffic/{email}","method":"post"},{"path":"/panel/api/clients/updateTraffic/{email}","method":"post"},{"path":"/panel/api/clients/ips/{email}","method":"post"},{"path":"/panel/api/clients/clearIps/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}/block","method":"post"},{"path":"/panel/api/clients/onlines","method":"post"},{"path":"/panel/api/clients/onlinesByGuid","method":"post"},{"path":"/panel/api/clients/clientIpsByGuid","method":"post"},{"path":"/panel/api/clients/activeInbounds","method":"post"},{"path":"/panel/api/clients/lastOnline","method":"post"},{"path":"/panel/api/clients/traffic/{email}","method":"get"},{"path":"/panel/api/clients/usageHistory/{email}","method":"get"},{"path":"/panel/api/clients/subLinks/{subId}","method":"get"},{"path":"/panel/api/clients/happLink/{id}","method":"post"},{"path":"/panel/api/clients/links/{email}","method":"get"}]} showTitle />
</>
);
}
+321 -3
View File
@@ -1903,6 +1903,140 @@
],
"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": {
@@ -9479,6 +9613,135 @@
}
}
},
"/panel/api/clients/attachCandidates": {
"get": {
"tags": [
"Clients"
],
"summary": "List up to 100 clients for the inbound attachment picker. Counts distinguish filtered rows and all eligible clients. A freeze request returns only the eligible count, maximum ID and a scope token covering the eligible IDs that match the given search and group for the chosen source and targets.",
"operationId": "get_panel_api_clients_attachCandidates",
"parameters": [
{
"name": "sourceId",
"in": "query",
"required": false,
"description": "Restrict candidates to clients on this inbound.",
"schema": {
"type": "integer"
}
},
{
"name": "inboundIds",
"in": "query",
"required": false,
"description": "Comma-separated target IDs. Required for freeze and if no source ID is specified.",
"schema": {
"type": "string"
}
},
{
"name": "page",
"in": "query",
"required": false,
"description": "1-indexed page, defaults to 1.",
"schema": {
"type": "integer"
}
},
{
"name": "search",
"in": "query",
"required": false,
"description": "Match email and either comment (with a source) or group.",
"schema": {
"type": "string"
}
},
{
"name": "group",
"in": "query",
"required": false,
"description": "Filter by exact group when there is no source.",
"schema": {
"type": "string"
}
},
{
"name": "freeze",
"in": "query",
"required": false,
"description": "Freeze the eligible IDs matching search and group, independently of page.",
"schema": {
"type": "boolean"
}
},
{
"name": "scopeSearch",
"in": "query",
"required": false,
"description": "Search a frozen selection was taken under; rows outside it report inScope false.",
"schema": {
"type": "string"
}
},
{
"name": "scopeGroup",
"in": "query",
"required": false,
"description": "Group a frozen selection was taken under; rows outside it report inScope false.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {
"$ref": "#/components/schemas/AttachCandidatePage"
}
}
},
"example": {
"success": true,
"obj": {
"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
}
}
}
}
}
}
}
},
"/panel/api/clients/list/paged": {
"get": {
"tags": [
@@ -11719,7 +11982,7 @@
"tags": [
"Clients"
],
"summary": "Attach many existing clients to many inbounds in one call. Each client keeps its identity (email/UUID/password/subId) and a shared traffic row; all clients are added to a target inbound in a single AddInboundClient call. Clients already present on a target are reported under skipped. Returns per-email attached/skipped/errors lists and triggers a single Xray restart if any target inbound was running.",
"summary": "Attach many existing clients to many inbounds in one call. Each client keeps its identity (email/UUID/password/subId) and a shared traffic row; all clients are added to a target inbound in a single AddInboundClient call. Clients already present on a target are reported under skipped. Explicit email requests return per-email lists. Alternatively submit selection with explicit clientIds or a frozen allMatching scopeToken plus excludedClientIds and the search and group it was frozen under. Scoped requests start a background job and return {jobId}. Poll GET /bulkAttach/:id for counts or a stale-selection error. Newer IDs stay outside the frozen scope. Changes to the frozen membership are rejected before applying changes. Triggers a single Xray restart if any target inbound was running.",
"operationId": "post_panel_api_clients_bulkAttach",
"requestBody": {
"required": true,
@@ -11733,7 +11996,11 @@
"items": {
"type": "string"
},
"description": "Emails of existing clients to attach."
"description": "Emails of existing clients to attach. Omit when using selection."
},
"selection": {
"type": "object",
"description": "Either {mode: \"explicit\", clientIds, sourceId?} or {mode: \"allMatching\", scopeToken, excludedClientIds?, search?, group?, sourceId?}."
},
"inboundIds": {
"type": "array",
@@ -11744,7 +12011,6 @@
}
},
"required": [
"emails",
"inboundIds"
]
},
@@ -11797,6 +12063,58 @@
}
}
},
"/panel/api/clients/bulkAttach/{id}": {
"get": {
"tags": [
"Clients"
],
"summary": "Poll a scoped attachment job. The result contains counts per target (attached, skipped, errors); an operation failure sets error instead. Completed results are retained for up to 15 minutes in the running panel process.",
"operationId": "get_panel_api_clients_bulkAttach_id",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "Job ID returned by the scoped bulkAttach request.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {
"$ref": "#/components/schemas/AttachJobStatus"
}
}
},
"example": {
"success": true,
"obj": {
"ended": "2025-01-01T00:00:00Z",
"error": "",
"result": null,
"running": false
}
}
}
}
}
}
}
},
"/panel/api/clients/bulkDetach": {
"post": {
"tags": [