fix(stats): remove duplicated entries in corpus explorer

This commit is contained in:
2026-04-01 00:22:29 +01:00
parent 430793cd09
commit 6378015726
2 changed files with 67 additions and 4 deletions

View File

@@ -66,6 +66,38 @@ const EMPTY_EXPLORER_STATE: ExplorerState = {
error: "",
};
const getExplorerRecordIdentity = (record: DatasetRecord) =>
JSON.stringify({
post_id: record.post_id ?? null,
parent_id: record.parent_id ?? null,
reply_to: record.reply_to ?? null,
author: record.author ?? null,
type: record.type ?? null,
timestamp: record.timestamp ?? null,
dt: record.dt ?? null,
title: record.title ?? null,
content: record.content ?? null,
source: record.source ?? null,
topic: record.topic ?? null,
});
const dedupeExplorerRecords = (records: DatasetRecord[]) => {
const uniqueRecords: DatasetRecord[] = [];
const seen = new Set<string>();
for (const record of records) {
const identity = getExplorerRecordIdentity(record);
if (seen.has(identity)) {
continue;
}
seen.add(identity);
uniqueRecords.push(record);
}
return uniqueRecords;
};
const normalizeRecordPayload = (payload: unknown): DatasetRecord[] => {
if (typeof payload === "string") {
try {
@@ -233,7 +265,9 @@ const StatPage = () => {
},
);
const normalizedRecords = normalizeRecordPayload(response.data);
const normalizedRecords = dedupeExplorerRecords(
normalizeRecordPayload(response.data),
);
setAllRecords(normalizedRecords);
setAllRecordsKey(filterKey);
@@ -254,7 +288,9 @@ const StatPage = () => {
try {
const records = await ensureFilteredRecords();
const context = buildExplorerContext(records);
const matched = records.filter((record) => spec.matcher(record, context));
const matched = dedupeExplorerRecords(
records.filter((record) => spec.matcher(record, context)),
);
matched.sort((a, b) => {
const aValue = String(a.dt ?? a.date ?? a.timestamp ?? "");
const bValue = String(b.dt ?? b.date ?? b.timestamp ?? "");
@@ -662,7 +698,7 @@ const StatPage = () => {
)}
{activeView === "interactional" && interactionData && (
<InteractionalStats data={interactionData} onExplore={openExplorer} />
<InteractionalStats data={interactionData} />
)}
{activeView === "interactional" && !interactionData && (