fix(wiki): count only the latest job per raw in KB failure stats

This commit is contained in:
matevip 2026-05-18 22:00:36 +08:00
parent 7949b6ff38
commit fb4206e356

View File

@ -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<Long, WikiProcessingJobEntity> 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();