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])
|
||||
|
||||
|
||||
Reference in new issue
Block a user