Skip to content

Commit 749a605

Browse files
committed
fix: deduplicate interview records from Supabase
- Add 3-layer dedup in syncWithSupabase after mapping DB records: 1. By DB id (primary) 2. By interview token (secondary) 3. By composite key: email+date+position (tertiary) - Keeps first occurrence (newest by created_at DESC) - Fix appData refresh: move DataStore.get() AFTER syncWithSupabase so rendering uses deduplicated data, not stale pre-sync data
1 parent 7ccd787 commit 749a605

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

dashboard/hr.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,21 @@ <h6 style="font-size:0.88rem;font-weight:700;margin-bottom:10px;display:flex;ali
28922892
proctorSettings: dbInt.proctor_settings || null
28932893
};
28942894
});
2895+
// DEDUP: Remove duplicate interview records (keep first = newest by created_at)
2896+
const seen = new Set();
2897+
data.interviews = data.interviews.filter(int => {
2898+
// Primary key: DB id
2899+
if (int.id && seen.has('id:' + int.id)) return false;
2900+
if (int.id) seen.add('id:' + int.id);
2901+
// Secondary key: token (unique per interview)
2902+
if (int.token && seen.has('tk:' + int.token)) return false;
2903+
if (int.token) seen.add('tk:' + int.token);
2904+
// Tertiary key: composite (email + date + position)
2905+
const ck = (int.candidateEmail + '|' + int.date + '|' + int.position).toLowerCase();
2906+
if (seen.has('ck:' + ck)) return false;
2907+
seen.add('ck:' + ck);
2908+
return true;
2909+
});
28952910
});
28962911
synced++;
28972912
} else if (intRes.error) {
@@ -4375,8 +4390,8 @@ <h3>${stats.tokenLinksGenerated}</h3>
43754390
});
43764391
});
43774392

4378-
appData = DataStore.get();
43794393
await syncWithSupabase();
4394+
appData = DataStore.get(); // Refresh AFTER sync so dedup data is used
43804395
renderInterviewTable();
43814396
renderCompletedInterviewTable();
43824397
renderCancelledInterviewTable();

0 commit comments

Comments
 (0)