perf(F5+): 行数据按需拉取(结果行版本信号)+ 修复 progress/light 恒判 missing
行数据按需拉取(审查 F5 后续): - V125 给 biz_file_result 补 updated_at(DEFAULT/ON UPDATE 由数据库维护, 实体标注 insertStrategy/updateStrategy=NEVER —— 否则 selectById→updateById 的 写回会把旧值写回去、ON UPDATE 不触发,版本信号静默冻结) - 装配器回传 rowsVersion=「最后变更时间毫秒#行数」,5 个品牌工具页版本未变即跳过 带行明细的重型 batch;前端变更信号为 rowsVersion + status/fileStatus/fileReady 复合 (任务收尾常见「行早写完、之后才置成功」,只看行版本会把界面卡在旧状态) 修复线上缺陷(同一功能验证时暴露): - TaskProgressLightAssembler 列裁剪漏选 module_type 却用它做模块过滤 → getModuleType() 恒为 null → light 恒把任务判成 missing;第七批把 light 接进 跟价/定时匹配/商品风险的轮询后,消费方会把运行中任务判为 FAILED - 补选中列 + 守卫用例 taskQueryMustSelectModuleType(已反向验证:去掉修复即红) - 前端 lightClaimsAllTasksMissing:整体性 missing 结论用重型端点复核后再采信 契约与文档:light 白名单补 rowsVersion(Java 契约测试 / spec 06 §2 / 12 个端点描述) 测试:mvn test 2901 全绿;前端 npm test 765 全绿
This commit is contained in:
+5
-3
@@ -25,7 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
class TaskProgressLightContractTest {
|
||||
|
||||
private static final Set<String> WHITELIST = new TreeSet<>(Set.of(
|
||||
"taskId", "status", "statusCode", "fileStatus", "fileError", "fileReady", "updatedAt"));
|
||||
// rowsVersion:结果行版本(「行数据按需拉取」信号,2026-09-14 加入),仍是轻量字段、不含行内容
|
||||
"taskId", "status", "statusCode", "fileStatus", "fileError", "fileReady", "updatedAt", "rowsVersion"));
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@@ -112,8 +113,9 @@ class TaskProgressLightContractTest {
|
||||
|
||||
@Test
|
||||
void commonShapeWhitelistOrderedDocumented() {
|
||||
// 回归门禁:与 spec 06 §2 白名单一致(taskId/status/statusCode?/fileStatus?/fileError?/fileReady?/updatedAt)
|
||||
assertEquals(List.of("fileError", "fileReady", "fileStatus", "status", "statusCode", "taskId", "updatedAt"),
|
||||
// 回归门禁:与 spec 06 §2 白名单一致(taskId/status/statusCode?/fileStatus?/fileError?/fileReady?/updatedAt
|
||||
// + 2026-09-14 新增 rowsVersion:结果行版本,行数据按需拉取的信号,仍是轻量字段)
|
||||
assertEquals(List.of("fileError", "fileReady", "fileStatus", "rowsVersion", "status", "statusCode", "taskId", "updatedAt"),
|
||||
new java.util.ArrayList<>(WHITELIST));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -120,7 +120,8 @@ class ResultFilePhaseContractTest {
|
||||
assertTrue(root.containsKey("items"), "响应必须含 items");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> first = ((java.util.List<Map<String, Object>>) root.get("items")).get(0);
|
||||
assertEquals(Set.of("taskId", "status", "statusCode", "fileStatus", "fileError", "fileReady", "updatedAt"),
|
||||
assertEquals(Set.of("taskId", "status", "statusCode", "fileStatus", "fileError", "fileReady", "updatedAt",
|
||||
"rowsVersion"),
|
||||
first.keySet(), "light 响应键集必须精确匹配白名单(无明细/payload/result 内容)");
|
||||
assertEquals(Boolean.TRUE, first.get("fileReady"));
|
||||
assertEquals("SUCCESS", first.get("fileStatus"));
|
||||
|
||||
+85
-1
@@ -3,7 +3,9 @@ package com.nanri.aiimage.modules.task.service;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.dto.TaskRowsVersionDto;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.model.vo.TaskProgressLightBatchVo;
|
||||
@@ -45,9 +47,10 @@ class TaskProgressLightAssemblerTest {
|
||||
}
|
||||
|
||||
private final FileTaskMapper fileTaskMapper = mock(FileTaskMapper.class);
|
||||
private final FileResultMapper fileResultMapper = mock(FileResultMapper.class);
|
||||
private final TaskFileJobService taskFileJobService = mock(TaskFileJobService.class);
|
||||
private final TaskProgressLightAssembler assembler =
|
||||
new TaskProgressLightAssembler(fileTaskMapper, taskFileJobService);
|
||||
new TaskProgressLightAssembler(fileTaskMapper, fileResultMapper, taskFileJobService);
|
||||
|
||||
private static FileTaskEntity task(long id, String moduleType, String status, LocalDateTime updatedAt) {
|
||||
FileTaskEntity t = new FileTaskEntity();
|
||||
@@ -203,4 +206,85 @@ class TaskProgressLightAssemblerTest {
|
||||
assertTrue(item.getFileReady() != null);
|
||||
assertTrue(item.getUpdatedAt() != null);
|
||||
}
|
||||
|
||||
/** 行数据按需拉取:light 端点回传结果行版本,格式「最后变更时间毫秒#行数」,无结果行时为 null。 */
|
||||
@Test
|
||||
void rowsVersionFromResultRows() {
|
||||
stubTasks(List.of(
|
||||
task(1L, "publish", "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 1)),
|
||||
task(2L, "publish", "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 2))));
|
||||
stubJobs(Map.of());
|
||||
LocalDateTime rowsUpdatedAt = LocalDateTime.of(2026, 8, 1, 11, 30, 5);
|
||||
when(fileResultMapper.selectRowsUpdatedAtByTaskIds(eq("publish"), anyList()))
|
||||
.thenReturn(List.of(new TaskRowsVersionDto(1L, rowsUpdatedAt, 3L)));
|
||||
|
||||
TaskProgressLightBatchVo vo = assembler.assemble("publish", null, List.of(1L, 2L));
|
||||
|
||||
String expected = rowsUpdatedAt
|
||||
.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli() + "#3";
|
||||
assertEquals(expected, vo.getItems().get(0).getRowsVersion());
|
||||
assertNull(vo.getItems().get(1).getRowsVersion(), "没有结果行的任务版本必须为 null");
|
||||
verify(fileResultMapper).selectRowsUpdatedAtByTaskIds(eq("publish"), anyList());
|
||||
}
|
||||
|
||||
/** 行数变化(行被删除)也要体现为版本变化;行数为空按 0 处理。 */
|
||||
@Test
|
||||
void rowsVersionCountsDeletedRows() {
|
||||
stubTasks(List.of(task(1L, "publish", "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 1))));
|
||||
stubJobs(Map.of());
|
||||
LocalDateTime rowsUpdatedAt = LocalDateTime.of(2026, 8, 1, 11, 30, 5);
|
||||
|
||||
when(fileResultMapper.selectRowsUpdatedAtByTaskIds(eq("publish"), anyList()))
|
||||
.thenReturn(List.of(new TaskRowsVersionDto(1L, rowsUpdatedAt, 5L)));
|
||||
String withFive = assembler.assemble("publish", null, List.of(1L)).getItems().get(0).getRowsVersion();
|
||||
|
||||
when(fileResultMapper.selectRowsUpdatedAtByTaskIds(eq("publish"), anyList()))
|
||||
.thenReturn(List.of(new TaskRowsVersionDto(1L, rowsUpdatedAt, 4L)));
|
||||
String withFour = assembler.assemble("publish", null, List.of(1L)).getItems().get(0).getRowsVersion();
|
||||
|
||||
assertFalse(withFive.equals(withFour), "同一时间戳下行数变化必须产生不同版本");
|
||||
|
||||
when(fileResultMapper.selectRowsUpdatedAtByTaskIds(eq("publish"), anyList()))
|
||||
.thenReturn(List.of(new TaskRowsVersionDto(1L, rowsUpdatedAt, null)));
|
||||
assertEquals(String.valueOf(rowsUpdatedAt
|
||||
.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli()) + "#0",
|
||||
assembler.assemble("publish", null, List.of(1L)).getItems().get(0).getRowsVersion(),
|
||||
"行数缺失按 0 计数");
|
||||
}
|
||||
|
||||
/** 任务全不存在时不应查结果行(避免无谓查询)。 */
|
||||
@Test
|
||||
void rowsVersionQuerySkippedWhenNoTasks() {
|
||||
stubTasks(List.of());
|
||||
stubJobs(Map.of());
|
||||
|
||||
TaskProgressLightBatchVo vo = assembler.assemble("publish", null, List.of(999L));
|
||||
|
||||
assertTrue(vo.getItems().isEmpty());
|
||||
verify(fileResultMapper, org.mockito.Mockito.never())
|
||||
.selectRowsUpdatedAtByTaskIds(any(), anyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 守卫:任务查询的选中列必须包含 module_type。
|
||||
*
|
||||
* <p>2026-09-14 线上事故——装配器用 {@code moduleType.equals(task.getModuleType())} 做模块过滤,
|
||||
* 但 select 只取 id/status/updated_at → getModuleType() 恒为 null → **所有任务被判 missing**。
|
||||
* 单测此前全绿是因为 mock 返回的是完整实体、不模拟列投影;第七批把 light 接进轮询后,
|
||||
* 消费方把 missing 当"任务已消失"(跟价页直接返回 FAILED),影响真实任务。
|
||||
*/
|
||||
@Test
|
||||
void taskQueryMustSelectModuleType() {
|
||||
stubTasks(List.of(task(1L, "publish", "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 1))));
|
||||
stubJobs(Map.of());
|
||||
|
||||
assembler.assemble("publish", null, List.of(1L));
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<FileTaskEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(fileTaskMapper).selectList(captor.capture());
|
||||
String select = captor.getValue().getSqlSelect();
|
||||
assertTrue(select != null && select.contains("module_type"),
|
||||
"选中列必须含 module_type,否则模块过滤把所有任务判成 missing(线上真实事故),实际=" + select);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ package com.nanri.aiimage.modules.task.service;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
@@ -33,9 +34,10 @@ import static org.mockito.Mockito.when;
|
||||
class TaskProgressLightPermissionTest {
|
||||
|
||||
private final FileTaskMapper fileTaskMapper = mock(FileTaskMapper.class);
|
||||
private final FileResultMapper fileResultMapper = mock(FileResultMapper.class);
|
||||
private final TaskFileJobService taskFileJobService = mock(TaskFileJobService.class);
|
||||
private final TaskProgressLightAssembler assembler =
|
||||
new TaskProgressLightAssembler(fileTaskMapper, taskFileJobService);
|
||||
new TaskProgressLightAssembler(fileTaskMapper, fileResultMapper, taskFileJobService);
|
||||
|
||||
private final List<FileTaskEntity> taskDb = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user