You've already forked DataMate
feat(annotation): 添加分段总数提示功能优化性能
- 在编辑器服务中添加 segment_total_hint 变量用于缓存分段总数计算结果 - 使用 with_for_update() 锁定查询以避免并发问题 - 将重复的分段总数计算逻辑替换为使用缓存的提示值 - 减少数据库查询次数提升标注任务处理效率 - 优化了分段索引存在时的总数获取流程
This commit is contained in:
@@ -992,11 +992,19 @@ class AnnotationEditorService:
|
|||||||
|
|
||||||
ls_task_id = self._make_ls_task_id(project_id, file_id)
|
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(
|
existing_result = await self.db.execute(
|
||||||
select(AnnotationResult).where(
|
select(AnnotationResult)
|
||||||
|
.where(
|
||||||
AnnotationResult.project_id == project_id,
|
AnnotationResult.project_id == project_id,
|
||||||
AnnotationResult.file_id == file_id,
|
AnnotationResult.file_id == file_id,
|
||||||
)
|
)
|
||||||
|
.with_for_update()
|
||||||
)
|
)
|
||||||
existing = existing_result.scalar_one_or_none()
|
existing = existing_result.scalar_one_or_none()
|
||||||
|
|
||||||
@@ -1026,7 +1034,7 @@ class AnnotationEditorService:
|
|||||||
if request.segment_index is not None:
|
if request.segment_index is not None:
|
||||||
segment_total = self._resolve_segment_total(final_payload)
|
segment_total = self._resolve_segment_total(final_payload)
|
||||||
if segment_total is None:
|
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:
|
if segment_total and segment_total > 0:
|
||||||
final_payload[SEGMENT_TOTAL_KEY] = segment_total
|
final_payload[SEGMENT_TOTAL_KEY] = segment_total
|
||||||
segment_done = len(self._extract_segment_annotations(final_payload))
|
segment_done = len(self._extract_segment_annotations(final_payload))
|
||||||
|
|||||||
Reference in New Issue
Block a user