Keep a remote listing and an office listing two roles in the per-place fold, since the kept role takes a copy's places and not its remote and the fetch gate then rejected the one behind the other
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f774b5147
commit
b4774f1da9
3 files changed
+31
-7
No files matched your search
+13
-4
@@ -82,6 +82,8 @@ class Copy:
|
|||||||
text: str = ""
|
text: str = ""
|
||||||
#: The link that opens this row on its host.
|
#: The link that opens this row on its host.
|
||||||
url: str = ""
|
url: str = ""
|
||||||
|
#: Whether the row is a remote role (`roles.remote` is 'remote').
|
||||||
|
remote: bool = False
|
||||||
|
|
||||||
|
|
||||||
def _country(c: Copy) -> str:
|
def _country(c: Copy) -> str:
|
||||||
@@ -191,9 +193,15 @@ def fold(rows: Iterable[Copy]) -> Folded:
|
|||||||
|
|
||||||
Within a `(company_key, title_key)` the kept rows of `assign` are grouped
|
Within a `(company_key, title_key)` the kept rows of `assign` are grouped
|
||||||
again, in `keep_order`: a row joins the first group whose members are all
|
again, in `keep_order`: a row joins the first group whose members are all
|
||||||
of its host and `similar` to it. Only a row with a link can be folded, as
|
of its host, `similar` to it and remote as it is or not. Only a row with
|
||||||
its link is what the kept role keeps. Every row of a merged group points
|
a link can be folded, as its link is what the kept role keeps. Every row
|
||||||
at its first row, the rows that pointed at a folded one included."""
|
of a merged group points at its first row, the rows that pointed at a
|
||||||
|
folded one included.
|
||||||
|
|
||||||
|
A remote listing and an office listing stay two roles: the kept role
|
||||||
|
takes a copy's places and not its remote, so the fetch gate, which reads
|
||||||
|
a remote role by its area, would reject the remote listing with an
|
||||||
|
office role elsewhere, and the office one with a remote role elsewhere."""
|
||||||
rows = list(rows)
|
rows = list(rows)
|
||||||
result = assign(rows)
|
result = assign(rows)
|
||||||
by_uid = {r.uid: r for r in rows}
|
by_uid = {r.uid: r for r in rows}
|
||||||
@@ -207,7 +215,8 @@ def fold(rows: Iterable[Copy]) -> Folded:
|
|||||||
groups: list[list[Copy]] = []
|
groups: list[list[Copy]] = []
|
||||||
for row in sorted(part, key=keep_order):
|
for row in sorted(part, key=keep_order):
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if all(m.host == row.host and similar(m.text, row.text) for m in group):
|
if all(m.host == row.host and m.remote == row.remote
|
||||||
|
and similar(m.text, row.text) for m in group):
|
||||||
group.append(row)
|
group.append(row)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -548,7 +548,8 @@ def rebuild_dupes(conn: sqlite3.Connection) -> DupeCounts:
|
|||||||
|
|
||||||
A copy the host published for another place (`dupes.Folded.placed`)
|
A copy the host published for another place (`dupes.Folded.placed`)
|
||||||
leaves its places on the kept role as `role_places` rows with the copy's
|
leaves its places on the kept role as `role_places` rows with the copy's
|
||||||
link, see `_sync_copy_places`."""
|
link, see `_sync_copy_places`. Its remote stays its own, which is why a
|
||||||
|
remote listing is never folded into an office one (`dupes.fold`)."""
|
||||||
# Migration 18 runs this on a file that has no `teaser` and no
|
# Migration 18 runs this on a file that has no `teaser` and no
|
||||||
# `role_places` yet: there it groups as before and folds no places.
|
# `role_places` yet: there it groups as before and folds no places.
|
||||||
current = any(r[1] == "teaser" for r in conn.execute("PRAGMA table_info(roles)"))
|
current = any(r[1] == "teaser" for r in conn.execute("PRAGMA table_info(roles)"))
|
||||||
@@ -556,7 +557,7 @@ def rebuild_dupes(conn: sqlite3.Connection) -> DupeCounts:
|
|||||||
rows = conn.execute(
|
rows = conn.execute(
|
||||||
f"""SELECT uid, company_key, title_key, country, place, {_HOST} AS host,
|
f"""SELECT uid, company_key, title_key, country, place, {_HOST} AS host,
|
||||||
description != '' AS described, posted_at,
|
description != '' AS described, posted_at,
|
||||||
SUBSTR({text}, 1, {dupes.TEXT_CHARS}), original_url
|
SUBSTR({text}, 1, {dupes.TEXT_CHARS}), original_url, remote = 'remote'
|
||||||
FROM roles
|
FROM roles
|
||||||
WHERE closed_at IS NULL AND company_key != ''
|
WHERE closed_at IS NULL AND company_key != ''
|
||||||
AND (company_key, title_key) IN (
|
AND (company_key, title_key) IN (
|
||||||
@@ -567,7 +568,7 @@ def rebuild_dupes(conn: sqlite3.Connection) -> DupeCounts:
|
|||||||
folded = made(
|
folded = made(
|
||||||
dupes.Copy(uid=r[0], company_key=r[1], title_key=r[2], country=r[3], place=r[4],
|
dupes.Copy(uid=r[0], company_key=r[1], title_key=r[2], country=r[3], place=r[4],
|
||||||
host=r[5], has_description=bool(r[6]), posted_at=r[7] or None,
|
host=r[5], has_description=bool(r[6]), posted_at=r[7] or None,
|
||||||
text=r[8] or "", url=r[9] or "")
|
text=r[8] or "", url=r[9] or "", remote=bool(r[10]))
|
||||||
for r in rows)
|
for r in rows)
|
||||||
new = folded.dup_of
|
new = folded.dup_of
|
||||||
old: dict[str, str | None] = dict.fromkeys(new)
|
old: dict[str, str | None] = dict.fromkeys(new)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ no network. The live cases are the 2026-09-29 database's."""
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
from dataclasses import replace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
@@ -238,6 +239,19 @@ def test_folding_needs_the_same_title_a_link_and_texts_that_can_be_one_job() ->
|
|||||||
assert fold([pc("1", "Berlin", a), pc("2", "Munich", "")]).placed == {"2"}
|
assert fold([pc("1", "Berlin", a), pc("2", "Munich", "")]).placed == {"2"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_remote_listing_is_not_folded_into_an_office_one() -> None:
|
||||||
|
"""The kept role takes a copy's places, not its remote, so the gate would
|
||||||
|
read "Remote, Germany" as an office role in Vienna and reject it for an
|
||||||
|
agent that takes remote roles. Two remote listings still fold."""
|
||||||
|
text = "We build the payment platform for our bank customers in Kotlin."
|
||||||
|
office = replace(pc("v", "Vienna", text), country="AT")
|
||||||
|
remote = replace(pc("r", "Remote, Germany", text), remote=True)
|
||||||
|
other = replace(pc("s", "Remote, Spain", text), country="ES", remote=True)
|
||||||
|
got = fold([office, remote, other])
|
||||||
|
assert got.dup_of == {"v": None, "r": None, "s": "r"}
|
||||||
|
assert got.placed == {"s"}
|
||||||
|
|
||||||
|
|
||||||
def test_a_copy_of_a_folded_row_follows_it_to_the_new_kept_role() -> None:
|
def test_a_copy_of_a_folded_row_follows_it_to_the_new_kept_role() -> None:
|
||||||
"""Berlin is kept over Munich; a second Munich row that was Munich's copy
|
"""Berlin is kept over Munich; a second Munich row that was Munich's copy
|
||||||
now points at Berlin, and is not a place of its own."""
|
now points at Berlin, and is not a place of its own."""
|
||||||
|
|||||||
Reference in new issue
Block a user