fix(production): 去掉我的生产任务列表工单详情 N+1 并避免批量任务截断
承接 #176 后生产侧残留:mine 列表不再对本页工单逐条打详情;list-by-work-orders / pageBy 拉取当页任务时避免 500 上限静默截断。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
90b62d96d7
commit
6aad64b7fb
4 files changed
+30
-18
No files matched your search
@@ -2340,24 +2340,32 @@ async def list_production_tasks_by_work_orders(
|
||||
return success_response(
|
||||
{"list": [], "total": 0, "page": 1, "pageSize": body.page_size, "totalPages": 0}
|
||||
)
|
||||
# 当前页工单卡片需要这些工单下的全部任务;避免单页 pageSize 上限静默截断
|
||||
effective_page_size = min(max(body.page_size, len(wo_ids) * 100), 500)
|
||||
items, total = production_task_svc.list_production_tasks(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
page=1,
|
||||
page_size=effective_page_size,
|
||||
work_order_ids=wo_ids,
|
||||
user_info=user,
|
||||
include_step_summary=body.include_step_summary,
|
||||
)
|
||||
tp = production_task_svc.total_pages(total, effective_page_size)
|
||||
all_items = []
|
||||
total = 0
|
||||
page = 1
|
||||
while page <= 20:
|
||||
items, total = production_task_svc.list_production_tasks(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
page=page,
|
||||
page_size=effective_page_size,
|
||||
work_order_ids=wo_ids,
|
||||
user_info=user,
|
||||
include_step_summary=body.include_step_summary,
|
||||
)
|
||||
all_items.extend(items or [])
|
||||
if not items or len(all_items) >= int(total or 0):
|
||||
break
|
||||
page += 1
|
||||
return success_response(
|
||||
{
|
||||
"list": items,
|
||||
"list": all_items,
|
||||
"total": total,
|
||||
"page": 1,
|
||||
"pageSize": effective_page_size,
|
||||
"totalPages": tp,
|
||||
"pageSize": len(all_items),
|
||||
"totalPages": 1 if all_items else 0,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1406,12 +1406,13 @@ def list_production_tasks(
|
||||
page_wo_ids = [wo.id for wo in page_work_orders if getattr(wo, "id", None)]
|
||||
if not page_wo_ids:
|
||||
return [], int(total)
|
||||
task_page_size = min(max(page_size * 100, len(page_wo_ids) * 20), 500)
|
||||
# 当页工单下全部匹配任务(工单页通常 ≤100);避免 500 上限静默截断卡片子任务
|
||||
task_fetch_cap = min(max(len(page_wo_ids) * 100, page_size * 100), 5000)
|
||||
rows = (
|
||||
_filtered()
|
||||
.filter(BizProductionTask.work_order_id.in_(page_wo_ids))
|
||||
.order_by(BizProductionTask.create_time.desc())
|
||||
.limit(task_page_size)
|
||||
.limit(task_fetch_cap)
|
||||
.all()
|
||||
)
|
||||
# 按工单页序重排;同工单内保持 create_time DESC
|
||||
|
||||
@@ -195,6 +195,10 @@ export async function fetchAllMineProductionTasks(
|
||||
return all
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 列表路径禁止使用:会对本页工单 N+1 打详情。
|
||||
* 「我的生产任务」卡片字段请用 buildWorkOrderFromTasks / buildMineTableRows。
|
||||
*/
|
||||
export async function enrichMineEntriesWithWorkOrders(
|
||||
entries: MineWorkOrderEntry[]
|
||||
): Promise<MineWorkOrderEntry[]> {
|
||||
|
||||
+2
-3
@@ -10,7 +10,6 @@ import {
|
||||
import {
|
||||
fetchMineProductionTasksByWorkOrderPage,
|
||||
groupMineTasksByWorkOrder,
|
||||
enrichMineEntriesWithWorkOrders,
|
||||
buildMineTableRows
|
||||
} from '@/utils/production-mine-task-groups'
|
||||
import {
|
||||
@@ -131,8 +130,8 @@ export function useProductionWorkOrderTabPage(
|
||||
excludeVoidProtocol: resolveExcludeVoidProtocolParam(),
|
||||
...buildPlannedStartTimeParams()
|
||||
})
|
||||
let entries = groupMineTasksByWorkOrder(pageRes.list || [])
|
||||
entries = await enrichMineEntriesWithWorkOrders(entries)
|
||||
// 与质检 mine 一致:工单卡片字段由任务聚合摘要构建,避免对本页工单 N+1 打详情
|
||||
const entries = groupMineTasksByWorkOrder(pageRes.list || [])
|
||||
const tableModel = buildMineTableRows(entries)
|
||||
tableData.value = tableModel.rows
|
||||
presetTasksByWorkOrderId.value = tableModel.presetTasksByWorkOrderId
|
||||
|
||||
Reference in new issue
Block a user