Tag a company All roles to read its big boards with the agents' wide reach; favourite scores only
Migration 21 adds companies.all_roles, tags every favourite of any agent and each company whose board had params {"reach": "all"} (logged per board, the param removed). reach.plan reads a tagged company's boards with the union of the enabled agents' require reach and the base reach; favourite no longer widens the fetch. POST /api/companies/{key}/all-roles sets it and queues a pull when on. The Companies list, the reader and the company strip draw the toggle beside the affinity buttons, the list filters on it, and the board's reach editor drops its All roles option.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d9a059e24
commit
5d5b7e7d3f
20 files changed
+422
-124
No files matched your search
+45
-3
@@ -18,7 +18,7 @@ import sqlite3
|
||||
from collections.abc import Callable
|
||||
|
||||
from app import places
|
||||
from app.models import SENIORITIES, company_fold, country_of, posted_at, posted_host
|
||||
from app.models import SENIORITIES, company_fold, company_key, country_of, posted_at, posted_host
|
||||
from app.seniority import from_title
|
||||
from app.storage import gazetteer
|
||||
|
||||
@@ -182,7 +182,9 @@ CREATE TABLE IF NOT EXISTS role_tags (
|
||||
-- worth checking by hand, 0 not; careers_opened_at when its careers page was
|
||||
-- last opened from there, which is also when a person last looked at it.
|
||||
-- hand_reason is why a person reads the careers page (models.HAND_REASONS),
|
||||
-- '' when nobody has to.
|
||||
-- '' when nobody has to. all_roles 1 reads every board of the company with
|
||||
-- the agents' wide reach, Europe today (app/jobs/reach.py); global, since
|
||||
-- fetching is shared.
|
||||
CREATE TABLE IF NOT EXISTS companies (
|
||||
key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
@@ -206,7 +208,8 @@ CREATE TABLE IF NOT EXISTS companies (
|
||||
last_funding INTEGER,
|
||||
last_funding_currency TEXT NOT NULL DEFAULT '',
|
||||
facts_source TEXT NOT NULL DEFAULT '',
|
||||
facts_at TEXT NOT NULL DEFAULT ''
|
||||
facts_at TEXT NOT NULL DEFAULT '',
|
||||
all_roles INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
-- Every folded spelling of a company (models.company_fold): orsted is Ørsted
|
||||
@@ -559,6 +562,11 @@ ALTER TABLE companies ADD COLUMN hand_reason TEXT NOT NULL DEFAULT '';
|
||||
# A Python step: the seed folds every name.
|
||||
(20, "company_aliases and the empty enrichment columns of companies",
|
||||
lambda conn: _add_company_aliases(conn)),
|
||||
# A Python step: params is JSON, the company is found by company_key and
|
||||
# each board that read everywhere is logged.
|
||||
(21, "companies.all_roles: a company tag that reads its boards with the agents' wide "
|
||||
"reach, given to every favourite and taking over a board's {\"reach\": \"all\"}",
|
||||
lambda conn: _add_all_roles(conn)),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
@@ -791,6 +799,40 @@ def _add_company_aliases(conn: sqlite3.Connection) -> None:
|
||||
log.info("migration 20: %d companies folded, %d folds shared", len(rows), len(clashes))
|
||||
|
||||
|
||||
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 21's step. The column; the tag for every company that is a
|
||||
favourite of any agent, since favourite no longer widens what a pull
|
||||
fetches and the tag does, so nothing read today is lost; and the tag for
|
||||
each company whose board's `params` held `{"reach": "all"}`, which the
|
||||
step removes from them. Such a board read everywhere and reads the wide
|
||||
reach from now on, so each is logged. Runs twice without harm."""
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(companies)")}
|
||||
if "all_roles" not in columns:
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN all_roles INTEGER NOT NULL DEFAULT 0")
|
||||
starred = conn.execute(
|
||||
"UPDATE companies SET all_roles=1 WHERE all_roles=0 AND key IN "
|
||||
"(SELECT company_key FROM agent_companies WHERE affinity=2)").rowcount
|
||||
log.info("migration 21: %d favourite companies tagged All roles", starred)
|
||||
for sub_id, target, company, label, raw in conn.execute(
|
||||
"SELECT id, target, company, label, params FROM subscriptions "
|
||||
"WHERE source = 'ats'").fetchall():
|
||||
try:
|
||||
params = json.loads(raw or "{}")
|
||||
except ValueError:
|
||||
continue
|
||||
if not isinstance(params, dict) or params.get("reach") != "all":
|
||||
continue
|
||||
del params["reach"]
|
||||
conn.execute("UPDATE subscriptions SET params=? WHERE id=?", (json.dumps(params), sub_id))
|
||||
key = company_key(company or label)
|
||||
if conn.execute("UPDATE companies SET all_roles=1 WHERE key=?", (key,)).rowcount:
|
||||
log.warning("migration 21: %s read all roles everywhere; %r is tagged All roles, "
|
||||
"which reads the agents' wide reach", target, key)
|
||||
else:
|
||||
log.warning("migration 21: %s read all roles everywhere, but %r has no company row "
|
||||
"to tag; it reads the agents' reach now", target, key)
|
||||
|
||||
|
||||
def user_version(conn: sqlite3.Connection) -> int:
|
||||
return int(conn.execute("PRAGMA user_version").fetchone()[0])
|
||||
|
||||
|
||||
+13
-3
@@ -116,7 +116,7 @@ _EXCERPT_RAW = 240
|
||||
_COMPANY_FIELDS = ("name", "domain", "status", "careers_url", "notes", "ats", "country", "city",
|
||||
"ats_slug", "watch", "careers_opened_at", "hand_reason", "sector", "stage",
|
||||
"size_band", "founded", "last_funding", "last_funding_currency",
|
||||
"facts_source", "facts_at")
|
||||
"facts_source", "facts_at", "all_roles")
|
||||
|
||||
#: A company as the store serves it: the row and the asked-for agent's affinity.
|
||||
_COMPANY_SELECT = """SELECT c.*, COALESCE(ac.affinity, 0) AS affinity FROM companies c
|
||||
@@ -1835,6 +1835,13 @@ class Store:
|
||||
self._alias(conn, key, fields["name"])
|
||||
return self._company(key)
|
||||
|
||||
def set_all_roles(self, key: str, on: bool) -> Company:
|
||||
"""Tag a company All roles, or untag it: its boards are read with the
|
||||
agents' wide reach, Europe today, from the next pull
|
||||
(`app/jobs/reach.py`). Global, not per agent. Raises KeyError for an
|
||||
unknown company."""
|
||||
return self.update_company(key, all_roles=int(bool(on)))
|
||||
|
||||
def remove_company(self, key: str) -> bool:
|
||||
"""Delete the row and every agent's stance on it, in one transaction:
|
||||
`agent_companies` holds the key with no foreign key to hold it back, so
|
||||
@@ -1891,8 +1898,8 @@ class Store:
|
||||
def merge_companies(self, keep: str, other: str) -> Company:
|
||||
"""Fold company `other` into `keep`, in one transaction: its roles and
|
||||
subscriptions move to `keep`, each agent's stance moves unless the
|
||||
agent has one on `keep` already, its aliases and its name become
|
||||
aliases of `keep`, and its row goes. Copies are not recomputed
|
||||
agent has one on `keep` already, an All roles tag carries over, its
|
||||
aliases and its name become aliases of `keep`, and its row goes. Copies are not recomputed
|
||||
(`rebuild_dupes`). Raises KeyError for an unknown company and
|
||||
ValueError for merging one into itself."""
|
||||
if keep == other:
|
||||
@@ -1915,6 +1922,9 @@ class Store:
|
||||
(keep, other))
|
||||
conn.execute("DELETE FROM company_aliases WHERE company_key=?", (other,))
|
||||
self._alias(conn, keep, rows[other])
|
||||
conn.execute("UPDATE companies SET all_roles = MAX(all_roles, "
|
||||
"(SELECT all_roles FROM companies WHERE key=?)) WHERE key=?",
|
||||
(other, keep))
|
||||
conn.execute("DELETE FROM companies WHERE key=?", (other,))
|
||||
return self._company(keep)
|
||||
|
||||
|
||||
Reference in new issue
Block a user