perf(ui): bound plan edit work and release finished BOM previews
This commit is contained in:
1 parent
b3883cfca1
commit
84d8f9c7f5
6 files changed
+99
-10
No files matched your search
@@ -0,0 +1,41 @@
|
||||
# 1.1.2 位号计划响应与内存审查
|
||||
|
||||
起点 `224f4e7`。本轮不打包;使用模拟库存、真实 Excel 和 Qt 事件循环进行验证,不启动 CAD。
|
||||
|
||||
## 已处理
|
||||
|
||||
- `ComponentTarget.key` 被循环调用时重复访问文件系统。500 个启用位号的规则编译原需 1500 次解析,同规模库存合并需 3500 次。增加单次校验内的 `ProjectIdentityResolver`,按原始路径字符串复用解析结果;编译、合并、数据库保存及 BOM 索引各有独立作用域。
|
||||
- BOM 表格路由重复解析同一个工程路径;改为仅在本次读表阶段复用,原生采集后不复用该路由缓存检查工程身份。
|
||||
- UI 修改一个单元格时,摘要会复制并统计全表,执行按钮保护又以元组成员查询扫描全部任务。现在模型维护启用数量,摘要读取源模型数量;任务 ID 使用集合,同次按钮更新只计算一次本批未保存状态。
|
||||
- 已保存或放弃的 BOM 报表仍强引用整份预览,包括原库存和计划。现在只释放结束的预览,保留校验行、数量和说明;未保存预览和失败后可重试的数据继续保留。
|
||||
|
||||
## 保护边界
|
||||
|
||||
解析器不跨刷新、采集或保存操作持续缓存;单独访问 `ComponentTarget.key` 仍即时解析。大小写规范、原理图/图页/UID、位号、旧料号、旧 Value 的比对仍保留。数据库事务、保存前基线复核、原生路径访问检查和恢复保护没有减少。
|
||||
|
||||
排序和筛选后的编辑继续按原始 UID 写回;摘要按当前工程全部源数据统计。只有相关 BOM 工程全部保存成功或明确放弃时,才释放报告中的预览引用。
|
||||
|
||||
## 本机测量
|
||||
|
||||
| 场景 | 优化前 | 优化后 |
|
||||
| --- | --- | --- |
|
||||
| 500 位号规则编译 | 0.543 秒 / 1500 次路径解析 | 0.00274 秒 / 1 次 |
|
||||
| 500 位号库存合并 | 1.299 秒 / 3500 次路径解析 | 0.00666 秒 / 1 次 |
|
||||
| 模拟 3000 任务、3000 位号,本地改单元格,5 次平均 | 41.56 毫秒 | 1.60 毫秒 |
|
||||
| 1000 模拟位号、200 行真实 XLSX 校验 | 上轮 5.920 秒 | 0.143 秒;200 行通过、0 行失败 |
|
||||
|
||||
这些数值只覆盖上述本地处理,不包含 CAD 启动、采集和实际替换。路径耗时为单次对照,不能视为所有机器的固定收益。
|
||||
|
||||
临时探针和结果保留在 build:
|
||||
|
||||
- `probe-plan-identity.py`;`plan-identity-before-20261015/metrics.json`、`plan-identity-after-20261015/metrics.json`。
|
||||
- `probe-local-plan-edit.py`;`local-plan-edit-before-20261015/metrics.json`、`local-plan-edit-after-20261015/metrics.json`。
|
||||
- `probe-bom-scale-audit.py`;`bom-scale-identity-after-20261015/metrics.json`。
|
||||
|
||||
## 验证
|
||||
|
||||
先复现重复解析和保存/放弃后预览未释放,再修正。路径用例还确认下一次操作会重新解析;弱引用用例确认预览可回收而报告仍可查看。
|
||||
|
||||
本轮针对目标身份、命令、恢复、BOM、库存扩展、长路径、UI、草稿和新轮次共 **169 passed,22.58 秒**。只读审查复核了缓存范围、完整基线字段、筛选统计和保存失败保护,未发现新的重要问题。未为本轮局部优化重复运行整套测试或 CAD。
|
||||
|
||||
仍待解决:CAD COM 偶发启动阻塞、千步执行的 30 秒目标,以及大执行模块进一步按职责整理。本轮不对这些项目作完成声明。
|
||||
@@ -276,6 +276,7 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
def _update_gates(self):
|
||||
busy = bool(self._workers) or self._loading
|
||||
state = execution_state(self._context, busy=busy, dirty=self.plan_panel.table.dirty)
|
||||
group_unsaved = self._group_has_unsaved_plans() if state.editable or state.new_round else False
|
||||
context = self._context
|
||||
self.run_panel.quick_run_button.setText(state.execute_text)
|
||||
self.run_panel.quick_run_button.setEnabled(state.execute)
|
||||
@@ -284,14 +285,14 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
self.run_panel.recover_button.setVisible(bool(context and context.interrupted))
|
||||
self.run_panel.recover_button.setEnabled(state.recover)
|
||||
self.run_panel.new_round_button.setVisible(bool(context and context.task.status is TaskStatus.COMPLETED))
|
||||
self.run_panel.new_round_button.setEnabled(state.new_round and not self._group_has_unsaved_plans())
|
||||
self.run_panel.new_round_button.setEnabled(state.new_round and not group_unsaved)
|
||||
self.run_panel.history_button.setVisible(bool(context and
|
||||
(context.has_evidence or context.task.status is TaskStatus.COMPLETED or context.task.summary.startswith('new round '))))
|
||||
self.run_panel.history_button.setEnabled(bool(context and not busy))
|
||||
self.run_panel.stop_queue_button.setVisible(self._batch_stop is not None)
|
||||
self.run_panel.stop_queue_button.setEnabled(bool(self._batch_stop and not self._batch_stop.is_set()))
|
||||
self.run_panel.copy_value_check.setEnabled(state.editable)
|
||||
rule_editable = state.editable and not self._group_has_unsaved_plans()
|
||||
rule_editable = state.editable and not group_unsaved
|
||||
self.mapping_table.set_rules_editable(rule_editable)
|
||||
self.plan_panel.set_plan_editable(state.editable, busy=busy)
|
||||
self.add_mapping_button.setEnabled(rule_editable)
|
||||
@@ -313,8 +314,8 @@ class TrialTaskCenterWindow(QMainWindow):
|
||||
self.task_list.delete_button.setText('彻底删除' if deleted else '删除')
|
||||
self.task_list.restore_button.setEnabled(deleted and not busy)
|
||||
grouped = bool(context and not context.legacy and context.task.group_id and not deleted)
|
||||
group_ids = tuple(t.task_id for t in self._tasks if context and t.group_id == context.task.group_id
|
||||
and t.status is not TaskStatus.DELETED)
|
||||
group_ids = {t.task_id for t in self._tasks if context and t.group_id == context.task.group_id
|
||||
and t.status is not TaskStatus.DELETED}
|
||||
group_dirty = self.plan_panel.has_unsaved_plan(group_ids)
|
||||
group_active = any(t.status in {TaskStatus.RUNNING, TaskStatus.PAUSED} for t in self._tasks if t.task_id in group_ids)
|
||||
self.task_list.queue_button.setEnabled(grouped and not busy and not group_dirty and not bool(context.interrupted))
|
||||
|
||||
@@ -343,6 +343,16 @@ class ProjectPlanPanel(QWidget):
|
||||
self._bom_batches.clear()
|
||||
self._orphaned_bom_batches.clear()
|
||||
self.table.dirty = False
|
||||
self._release_bom_previews()
|
||||
|
||||
def _release_bom_previews(self, saved=None):
|
||||
for scope, (report, text, title) in tuple(self._bom_reports.items()):
|
||||
preview = report.preview
|
||||
if preview is not None and (saved is None or all(p.task_id in saved for p in preview.projects)):
|
||||
text = '\n'.join(text.splitlines()[:-1]) + ('\n校验通过,位号计划已保存。' if saved is not None
|
||||
else '\n本次导入预览已放弃,校验报告保留。')
|
||||
self._bom_reports[scope] = (replace(report, preview=None), text, title)
|
||||
self._restore_bom_report(self._report_scope(self.task_id))
|
||||
|
||||
def cancel_operation(self):
|
||||
if self._operation_stop is not None:
|
||||
@@ -372,19 +382,19 @@ class ProjectPlanPanel(QWidget):
|
||||
self.summary.setText(message)
|
||||
|
||||
def _summary(self):
|
||||
rows = self.table.rows()
|
||||
count = self.table.plan_model.rowCount()
|
||||
batch = self._active_bom_batch()
|
||||
self.save_button.setText('保存本批位号计划' if batch else '保存位号计划')
|
||||
if batch:
|
||||
self.summary.setText(f'本批 BOM 已匹配 {len(batch.projects)} 个工程;表格显示当前工程,切换任务可编辑,'
|
||||
'确认后一次保存本批位号计划。')
|
||||
return
|
||||
if not rows:
|
||||
if not count:
|
||||
self.summary.setText('先添加旧、新料号规则,再采集位号;可直接编辑,Excel 导入导出为可选操作。')
|
||||
if rows:
|
||||
selected = sum(row.enabled for row in rows)
|
||||
if count:
|
||||
selected = self.table.plan_model.enabled_count
|
||||
suffix = ';有未保存编辑,请先保存' if self.table.dirty else ''
|
||||
self.summary.setText(f'当前工程:{len(rows)} 个位号,替换 {selected} 个、保留 {len(rows)-selected} 个{suffix}。同步 NC 按行设置。')
|
||||
self.summary.setText(f'当前工程:{count} 个位号,替换 {selected} 个、保留 {count-selected} 个{suffix}。同步 NC 按行设置。')
|
||||
|
||||
def _changed(self):
|
||||
self._summary()
|
||||
@@ -399,7 +409,7 @@ class ProjectPlanPanel(QWidget):
|
||||
if self._active_bom_batch():
|
||||
self.collect_button.setEnabled(False)
|
||||
self.export_button.setEnabled(self._editable and bool(self.task_id)
|
||||
and bool(self.table.rows()) and not self.table.dirty)
|
||||
and bool(self.table.plan_model.rowCount()) and not self.table.dirty)
|
||||
self.export_bom_button.setEnabled(not busy)
|
||||
|
||||
def _dispatch(self, operation, callback, button):
|
||||
@@ -559,6 +569,7 @@ class ProjectPlanPanel(QWidget):
|
||||
self._changed()
|
||||
|
||||
def _saved_bom_batch(self, saved):
|
||||
self._release_bom_previews(saved)
|
||||
for task_id in saved:
|
||||
self._drafts.pop(task_id, None)
|
||||
self._orphaned_bom_batches.pop(task_id, None)
|
||||
|
||||
@@ -12,6 +12,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.rows = []
|
||||
self.enabled_count = 0
|
||||
self.search_text = []
|
||||
self.editable = True
|
||||
@staticmethod
|
||||
@@ -22,6 +23,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
def populate(self, rows):
|
||||
self.beginResetModel()
|
||||
self.rows = list(rows)
|
||||
self.enabled_count = sum(row.enabled for row in self.rows)
|
||||
self.search_text = [self.searchable(row) for row in self.rows]
|
||||
self.endResetModel()
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
@@ -68,6 +70,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
updated = replace(self.rows[number], **change)
|
||||
if updated == self.rows[number]:
|
||||
return False
|
||||
self.enabled_count += int(updated.enabled) - int(self.rows[number].enabled)
|
||||
self.rows[number] = updated
|
||||
self.search_text[number] = self.searchable(updated)
|
||||
self.dataChanged.emit(index, index, [role, Qt.ItemDataRole.DisplayRole])
|
||||
@@ -83,6 +86,7 @@ class TargetPlanModel(QAbstractTableModel):
|
||||
for number in numbers:
|
||||
updated = replace(self.rows[number], **{field: value})
|
||||
if updated != self.rows[number]:
|
||||
self.enabled_count += int(updated.enabled) - int(self.rows[number].enabled)
|
||||
self.rows[number] = updated
|
||||
self.search_text[number] = self.searchable(updated)
|
||||
changed.append(number)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from pathlib import Path
|
||||
import gc
|
||||
import weakref
|
||||
|
||||
import pytest
|
||||
from openpyxl import load_workbook
|
||||
@@ -185,3 +187,32 @@ def test_ui_previews_each_project_and_confirms_the_batch_once(batch, tmp_path, q
|
||||
assert not window.plan_panel.has_unsaved_plan(tuple(task.task_id for task in tasks))
|
||||
assert window.run_panel.quick_run_button.isEnabled()
|
||||
window.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action', ['save', 'discard'])
|
||||
def test_finished_bom_preview_is_released_while_report_remains(batch, tmp_path, qtbot, action):
|
||||
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
|
||||
service, store, tasks, targets, calls = batch
|
||||
window = TrialTaskCenterWindow(service, close_plan_confirmer=lambda: 'discard')
|
||||
qtbot.addWidget(window)
|
||||
window.open_task(tasks[0].task_id)
|
||||
qtbot.waitUntil(lambda: not window._loading and not window._context_query.busy)
|
||||
path = write_bom_template(tmp_path / 'release.xlsx', records_for(tasks, targets))
|
||||
panel = window.plan_panel
|
||||
report = service.inspect_bom_batch(tasks[0].task_id, path)
|
||||
preview = weakref.ref(report.preview)
|
||||
panel._received_bom_report(report)
|
||||
del report
|
||||
assert panel.last_bom_report.preview is not None
|
||||
if action == 'save':
|
||||
saved = service.save_bom_batch(panel.last_bom_report.preview,
|
||||
{p.task_id: p.rows for p in panel.last_bom_report.preview.projects})
|
||||
panel._saved_bom_batch(saved)
|
||||
else:
|
||||
panel.discard_all()
|
||||
qtbot.waitUntil(lambda: not window._loading and not window._context_query.busy)
|
||||
gc.collect()
|
||||
assert preview() is None, 'finished report retains the full component preview'
|
||||
assert panel.last_bom_report.passed_rows == 2
|
||||
assert '通过 2 行' in panel.bom_report.toPlainText()
|
||||
window.close()
|
||||
@@ -56,6 +56,7 @@ def test_original_window_edits_target_plan_and_nc_without_export(qtbot, tmp_path
|
||||
table = window.plan_panel.table
|
||||
table.model().setData(table.model().index(0, 0), Qt.CheckState.Checked, Qt.ItemDataRole.CheckStateRole)
|
||||
table.model().setData(table.model().index(0, 9), Qt.CheckState.Unchecked, Qt.ItemDataRole.CheckStateRole)
|
||||
assert '替换 1 个、保留 1 个' in window.plan_panel.summary.text()
|
||||
assert not window.run_panel.quick_run_button.isEnabled()
|
||||
assert window.plan_panel.export_bom_button.isEnabled()
|
||||
window.plan_panel.save()
|
||||
|
||||
Reference in new issue
Block a user