From 5a5279869eba4ac361ba7aef0db65a7c7d3a80c7 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 31 Jan 2026 16:28:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(annotation):=20=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E6=AE=B5=E6=80=BB=E6=95=B0=E6=8F=90=E7=A4=BA=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编辑器服务中添加 segment_total_hint 变量用于缓存分段总数计算结果 - 使用 with_for_update() 锁定查询以避免并发问题 - 将重复的分段总数计算逻辑替换为使用缓存的提示值 - 减少数据库查询次数提升标注任务处理效率 - 优化了分段索引存在时的总数获取流程 --- .../app/module/annotation/service/editor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/datamate-python/app/module/annotation/service/editor.py b/runtime/datamate-python/app/module/annotation/service/editor.py index 1cd5587..878c389 100644 --- a/runtime/datamate-python/app/module/annotation/service/editor.py +++ b/runtime/datamate-python/app/module/annotation/service/editor.py @@ -992,11 +992,19 @@ class AnnotationEditorService: ls_task_id = self._make_ls_task_id(project_id, file_id) + segment_total_hint = None + if request.segment_index is not None: + segment_total_hint = self._resolve_segment_total(annotation_payload) + if segment_total_hint is None: + segment_total_hint = await self._compute_segment_total(project, file_record, file_id) + existing_result = await self.db.execute( - select(AnnotationResult).where( + select(AnnotationResult) + .where( AnnotationResult.project_id == project_id, AnnotationResult.file_id == file_id, ) + .with_for_update() ) existing = existing_result.scalar_one_or_none() @@ -1026,7 +1034,7 @@ class AnnotationEditorService: if request.segment_index is not None: segment_total = self._resolve_segment_total(final_payload) if segment_total is None: - segment_total = await self._compute_segment_total(project, file_record, file_id) + segment_total = segment_total_hint if segment_total and segment_total > 0: final_payload[SEGMENT_TOTAL_KEY] = segment_total segment_done = len(self._extract_segment_annotations(final_payload))