diff --git a/mateclaw-server/src/main/java/vip/mate/wiki/controller/WikiRelationController.java b/mateclaw-server/src/main/java/vip/mate/wiki/controller/WikiRelationController.java index 484be855..d309e598 100644 --- a/mateclaw-server/src/main/java/vip/mate/wiki/controller/WikiRelationController.java +++ b/mateclaw-server/src/main/java/vip/mate/wiki/controller/WikiRelationController.java @@ -15,6 +15,7 @@ import vip.mate.wiki.model.WikiPageEntity; import vip.mate.wiki.repository.WikiPageCitationMapper; import vip.mate.wiki.service.*; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -96,12 +97,21 @@ public class WikiRelationController { long enrichedCount = pageService.listByKbIdWithContent(kbId).stream() .filter(p -> p.getContent() != null && p.getContent().contains("[[")) .count(); - // Use listByKbId (all statuses) instead of listQueued (queued-only) + // Use listByKbId (all statuses) instead of listQueued (queued-only). + // A raw material accumulates one job row per (re)processing attempt; + // only its most recent job reflects current state. Collapse to the + // latest job per raw (highest snowflake id wins) so a failed attempt + // that a later successful reprocess superseded stops being counted. var allJobs = jobMapper.listByKbId(kbId, 200); - int failedJobCount = (int) allJobs.stream() + Map latestByRaw = new HashMap<>(); + for (WikiProcessingJobEntity job : allJobs) { + latestByRaw.merge(job.getRawId(), job, + (a, b) -> a.getId() >= b.getId() ? a : b); + } + int failedJobCount = (int) latestByRaw.values().stream() .filter(j -> "failed".equals(j.getStatus())) .count(); - int runningJobCount = (int) allJobs.stream() + int runningJobCount = (int) latestByRaw.values().stream() .filter(j -> "running".equals(j.getStatus())) .count();