fix: keep earliest Apec bridge survivor
This commit is contained in:
parent
debaab0947
commit
5fefa3aab1
@ -51,6 +51,8 @@ def _repoint_listing_aliases(
|
||||
def dedupe_apec_listings(listings: list[ApecListing]) -> list[ApecListing]:
|
||||
url_to_listing: dict[str, ApecListing] = {}
|
||||
source_job_id_to_listing: dict[str, ApecListing] = {}
|
||||
survivor_order: dict[int, int] = {}
|
||||
next_order = 0
|
||||
deduped: list[ApecListing] = []
|
||||
|
||||
for listing in listings:
|
||||
@ -68,17 +70,20 @@ def dedupe_apec_listings(listings: list[ApecListing]) -> list[ApecListing]:
|
||||
|
||||
if not matches:
|
||||
deduped.append(listing)
|
||||
survivor_order[id(listing)] = next_order
|
||||
next_order += 1
|
||||
_register_listing(url_to_listing, source_job_id_to_listing, listing, listing)
|
||||
continue
|
||||
|
||||
survivor = matches[0]
|
||||
for other in matches[1:]:
|
||||
survivor = min(matches, key=lambda candidate: survivor_order[id(candidate)])
|
||||
for other in matches:
|
||||
if other is survivor:
|
||||
continue
|
||||
|
||||
_merge_listing_metadata(survivor, other)
|
||||
deduped[:] = [item for item in deduped if item is not other]
|
||||
_repoint_listing_aliases(url_to_listing, source_job_id_to_listing, other, survivor)
|
||||
survivor_order.pop(id(other), None)
|
||||
|
||||
_merge_listing_metadata(survivor, listing)
|
||||
_register_listing(url_to_listing, source_job_id_to_listing, listing, survivor)
|
||||
|
||||
@ -178,3 +178,32 @@ def test_dedupe_apec_listings_keeps_one_survivor_for_cluster_alias_chain() -> No
|
||||
assert len(deduped) == 1
|
||||
assert deduped[0].url == "u2"
|
||||
assert deduped[0].source_job_id == "id2"
|
||||
|
||||
|
||||
def test_dedupe_apec_listings_keeps_first_listing_as_bridge_survivor() -> None:
|
||||
first = ApecListing(
|
||||
source="apec",
|
||||
source_job_id="id1",
|
||||
url="u1",
|
||||
fetched_at="2026-06-01T10:00:00Z",
|
||||
)
|
||||
second = ApecListing(
|
||||
source="apec",
|
||||
source_job_id="id2",
|
||||
url="u2",
|
||||
fetched_at="2026-06-01T10:01:00Z",
|
||||
)
|
||||
third = ApecListing(
|
||||
source="apec",
|
||||
source_job_id="id1",
|
||||
url="u2",
|
||||
company="NewestCo",
|
||||
fetched_at="2026-06-01T10:02:00Z",
|
||||
)
|
||||
|
||||
deduped = dedupe_apec_listings([first, second, third])
|
||||
|
||||
assert len(deduped) == 1
|
||||
assert deduped[0].url == "u1"
|
||||
assert deduped[0].source_job_id == "id1"
|
||||
assert deduped[0].company == "NewestCo"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user