task-11: Coze 结果合并前按稳定 rowKey HashSet 去重,消除 O(n²) 重复处理
This commit is contained in:
+27
-1
@@ -1533,6 +1533,30 @@ public class SimilarAsinTaskService {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task 11:Coze 结果合并前按稳定 rowKey 一次性去重。
|
||||
* 优先 rowToken,缺失时回退归一化的 legacy key(id::ASIN::country),
|
||||
* 保留首次出现顺序。合并路径此前对每个重复行都重复 expand/分配/写回,是 O(n²) 热点。
|
||||
*/
|
||||
List<SimilarAsinResultRowDto> dedupeRowsByRowKey(List<SimilarAsinResultRowDto> cozeRows) {
|
||||
List<SimilarAsinResultRowDto> deduped = new ArrayList<>();
|
||||
if (cozeRows == null || cozeRows.isEmpty()) {
|
||||
return deduped;
|
||||
}
|
||||
Set<String> seenKeys = new java.util.HashSet<>();
|
||||
for (SimilarAsinResultRowDto row : cozeRows) {
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String key = rowKey(row);
|
||||
if (key.isBlank() || !seenKeys.add(key)) {
|
||||
continue;
|
||||
}
|
||||
deduped.add(row);
|
||||
}
|
||||
return deduped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task 10:基于 rowKey 索引为 coze 回传行分配归属 chunk。
|
||||
* 命中索引 → 归属该 chunk;未命中且有有效 fallback(chunkScopeHash + chunkIndex)
|
||||
@@ -3849,8 +3873,10 @@ public class SimilarAsinTaskService {
|
||||
rowsByChunk.put(chunkKey, readChunkRows(chunk));
|
||||
chunkByKey.put(chunkKey, chunk);
|
||||
}
|
||||
// Task 11:合并前按稳定 rowKey 去重,消除重复行逐行 expand/分配/写回 的 O(n²) 热点。
|
||||
List<SimilarAsinResultRowDto> uniqueRows = dedupeRowsByRowKey(cozeRows);
|
||||
List<SimilarAsinResultRowDto> expandedAll = new ArrayList<>();
|
||||
for (SimilarAsinResultRowDto resultRow : cozeRows) {
|
||||
for (SimilarAsinResultRowDto resultRow : uniqueRows) {
|
||||
expandedAll.addAll(expandRows(List.of(resultRow), allRowsByBaseId));
|
||||
}
|
||||
// Task 10:先建 rowKey → chunkKey 批量索引,把逐 chunk 线性扫描降为 O(1) 查找。
|
||||
|
||||
Reference in New Issue
Block a user