sort dupe files based on upload timestamp rather than id

This commit is contained in:
Daniel Roth 2026-06-30 11:06:58 +00:00
parent ac6983ae68
commit 7c9faba215

View file

@ -48,7 +48,9 @@ export async function GET(req: Request) {
const latestByS3Key = new Map<string, (typeof rows)[number]>();
for (const row of rows) {
const existing = latestByS3Key.get(row.s3FileKey);
if (!existing || row.id > existing.id) latestByS3Key.set(row.s3FileKey, row);
if (!existing || row.s3UploadTimestamp > existing.s3UploadTimestamp) {
latestByS3Key.set(row.s3FileKey, row);
}
}
// Step 2: among distinct keys, same (fileType, measureName) → keep latest.
@ -59,7 +61,9 @@ export async function GET(req: Request) {
if (!row.fileType) { unclassified.push(row); continue; }
const key = `${row.fileType}:${row.measureName ?? ""}`;
const existing = latestByDocType.get(key);
if (!existing || row.id > existing.id) latestByDocType.set(key, row);
if (!existing || row.s3UploadTimestamp > existing.s3UploadTimestamp) {
latestByDocType.set(key, row);
}
}
const dedupedRows = [...latestByDocType.values(), ...unclassified];