Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/extension/src/lib/core/scoring/dedup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ const tokenize = (text: string | null | undefined): Set<string> =>
.filter((token) => token.length > 1 && !STOP_WORDS.has(token))
);

/**
* True if any member of `needles` is present in `tokens`. Iterates `needles`
* (typically a tiny constant set such as REMOTE_LOCATION_TOKENS) and does O(1)
* membership checks against `tokens`, allocating nothing. Replaces the previous
* `[...aTokens, ...bTokens].some(...)` in compareLocations, which allocated a
* merged array on every candidate pair — a hot path during deduplication.
*/
const hasAnyToken = (tokens: Set<string>, needles: Set<string>): boolean => {
for (const needle of needles) {
if (tokens.has(needle)) {
return true;
}
}
return false;
};

/**
* Counts shared elements between two sets, iterating the smaller set to minimise
* membership checks. Allocates no intermediate arrays/sets — important because
Expand Down Expand Up @@ -316,7 +332,8 @@ const compareLocations = (
const hasRemoteContext =
a.remote === 'full' ||
b.remote === 'full' ||
[...aTokens, ...bTokens].some((token) => REMOTE_LOCATION_TOKENS.has(token));
hasAnyToken(aTokens, REMOTE_LOCATION_TOKENS) ||
hasAnyToken(bTokens, REMOTE_LOCATION_TOKENS);

return { compatible: hasRemoteContext, score: hasRemoteContext ? 0.4 : 0 };
};
Expand Down
28 changes: 28 additions & 0 deletions apps/extension/tests/unit/scoring/dedup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,34 @@ describe('deduplicateMissions', () => {
expect(result).toHaveLength(2);
});

it('dedupes across disjoint locations when one carries a remote token', () => {
// Exercises the compareLocations remote-context fallback: location token
// sets are disjoint (no weighted similarity), but "teletravail" is in
// REMOTE_LOCATION_TOKENS, so the pair stays compatible and merges.
// Regression guard for the allocation-free hasAnyToken implementation.
const missions = [
makeMission({
id: 'paris',
title: 'Developpeur React Senior',
stack: ['React', 'TypeScript'],
location: 'Paris',
remote: null,
}),
makeMission({
id: 'remote',
title: 'Developpeur React Senior',
stack: ['React'],
location: 'Teletravail',
remote: null,
}),
];

const result = deduplicateMissionsDetailed(missions);
expect(result.missions).toHaveLength(1);
expect(result.duplicateRelations).toHaveLength(1);
expect(result.duplicateRelations[0].confidence).toBeGreaterThanOrEqual(0.8);
});

it('handles complex duplicate scenarios', () => {
const missions = [
makeMission({
Expand Down
Loading