perf(fulfillment): 优化本地能力选号查询与索引

This commit is contained in:
yml
2026-11-23 18:53:06 +08:00
parent d5422b0ecd
commit 7e0d27927c
23 changed files with 1624 additions and 95 deletions
@@ -362,6 +362,9 @@ def _task_out(
)
collab_order = resolved.collab_orders.get(int(task.id))
bind_result = (bind_task.result or {}) if bind_task else {}
account_binding_confirmed = bool(
account is not None and account.role_bind_status == "bound"
)
effective_issue = _effective_binding_issue(task, bind_task, bind_result)
effective_last_error = _effective_task_message(task, effective_issue)
exchange_task_id = task.exchange_task_id
@@ -377,7 +380,11 @@ def _task_out(
.scalar()
)
# 外层只消费共享绑定规则,不再自己比较角色名或 bindAct。
pending_role = pending_binding_role_from_result(bind_result)
pending_role = (
""
if account_binding_confirmed or task.binding_status == "bound"
else pending_binding_role_from_result(bind_result)
)
sale_mode = classification.normalize_sale_mode(task.sale_mode)
availability = classification.availability_state(
sale_mode=sale_mode,
@@ -477,12 +484,19 @@ def _task_out(
"status": bind_task.status,
"message": bind_task.message,
"qrUrl": str(bind_result.get("url") or "") if include_qr else "",
"roleName": binding_role_from_result(bind_result),
"roleName": (
str(account.game_name or "")
if account_binding_confirmed and account is not None
else binding_role_from_result(bind_result)
),
"areaName": str(bind_result.get("area_name") or ""),
"platName": str(bind_result.get("plat_name") or ""),
"bindPhase": str(bind_result.get("bind_phase") or ""),
"bindReadyForConfirm": bool(pending_role),
"bindConfirmed": bool(bind_result.get("bind_confirmed")),
"bindConfirmed": bool(
account_binding_confirmed
or bind_result.get("bind_confirmed")
),
}
if bind_task
else None
@@ -620,7 +634,15 @@ def customer_binding_out(db: Session, task_id: int) -> dict[str, Any]:
else None
)
bind_result = (bind_task.result or {}) if bind_task else {}
pending_role = pending_binding_role_from_result(bind_result)
account = db.get(Account, int(task.account_id)) if task.account_id else None
account_binding_confirmed = bool(
account is not None and account.role_bind_status == "bound"
)
pending_role = (
""
if account_binding_confirmed or task.binding_status == "bound"
else pending_binding_role_from_result(bind_result)
)
effective_issue = _effective_binding_issue(task, bind_task, bind_result)
lease = (
db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
@@ -657,11 +679,18 @@ def customer_binding_out(db: Session, task_id: int) -> dict[str, Any]:
"qrUrl": str(bind_result.get("url") or ""),
"qrGeneratedAt": str(bind_result.get("qr_generated_at") or ""),
"qrExpiresAt": str(bind_result.get("qr_expires_at") or ""),
"roleName": binding_role_from_result(bind_result),
"roleName": (
str(account.game_name or "")
if account_binding_confirmed and account is not None
else binding_role_from_result(bind_result)
),
"areaName": str(bind_result.get("area_name") or ""),
"platName": str(bind_result.get("plat_name") or ""),
"bindReadyForConfirm": (bool(pending_role) and not binding_failed),
"bindConfirmed": bool(bind_result.get("bind_confirmed")) and binding_confirmed,
"bindConfirmed": bool(
binding_confirmed
and (account_binding_confirmed or bind_result.get("bind_confirmed"))
),
"queueState": queue_state,
"retryAfterMs": retry_after_ms,
"queueLane": bind_task.queue_lane if bind_task else "",