mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
sort dupe files based on upload timestamp rather than id
This commit is contained in:
parent
ac6983ae68
commit
7c9faba215
1 changed files with 6 additions and 2 deletions
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue