Serve one alpha page: filters, roles, the tracker, and Jobs
/, GET /api/roles|companies|applications, POST /api/companies/{key}/affinity
and /api/applications[/{id}/status]. The Jinja2 template renders an empty
shell; static/app.js fills it and drives Save, affinity and status changes.
<desk-jobs> from pipeline.web mounts at the bottom so Pull can be started
from the page.
Store.roles gains q, function, remote, days and hide_muted, and company/
place move from a key match to a substring on the text a board wrote.
hide_muted filters in SQL before LIMIT: filtering after it shipped first and
broke immediately on real data, since Databricks' freshly pulled 884 roles
were the newest 200-plus rows in the table and muting it left nothing to
show.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
867ebe6405
commit
b44f78ca7e
13 files changed
+1143
-22
No files matched your search
@@ -12,7 +12,7 @@ import json
|
||||
import sqlite3
|
||||
from collections.abc import Callable, Iterator, MutableMapping, Sequence
|
||||
from contextlib import closing, contextmanager
|
||||
from datetime import UTC, datetime
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
@@ -51,6 +51,13 @@ def _remote(value: Any) -> str:
|
||||
return text if text in REMOTE else ""
|
||||
|
||||
|
||||
def _like(text: str) -> str:
|
||||
"""A `LIKE` pattern for a case-insensitive substring match, with SQLite's
|
||||
own wildcards escaped so a search for "50%" or "a_b" stays literal."""
|
||||
escaped = text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
|
||||
return f"%{escaped}%"
|
||||
|
||||
|
||||
def _int_or_none(value: Any) -> int | None:
|
||||
if value is None or value == "" or isinstance(value, bool):
|
||||
return None
|
||||
@@ -204,18 +211,48 @@ class Store:
|
||||
return Role.from_row(row) if row else None
|
||||
|
||||
def roles(self, limit: int = 100, company: str | None = None,
|
||||
place: str | None = None, open_only: bool = True) -> list[Role]:
|
||||
"""Newest first by `first_seen`. `company` and `place` are matched by
|
||||
key, so any spelling that keys the same finds the same rows."""
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
remote: str | None = None, days: int | None = None,
|
||||
hide_muted: bool = False) -> list[Role]:
|
||||
"""Newest first by `first_seen`. `company` and `place` are
|
||||
case-insensitive substrings of the columns a board wrote — not the
|
||||
key, so a search does not have to know the exact slug a company folds
|
||||
to. `q` is matched word by word against `title`; a role must match
|
||||
every word. `function` and `remote` match a gate column exactly.
|
||||
`days` keeps only roles first seen within that many days of now.
|
||||
|
||||
`hide_muted` excludes a muted company's roles before `limit` is
|
||||
applied, in SQL rather than after the fact: a company that has
|
||||
published a lot, all at once — a fresh board added, a re-pull that
|
||||
finally reached it — can otherwise fill the whole page with roles
|
||||
that then all turn out to be from the one company someone muted,
|
||||
leaving nothing to show for a default query that would otherwise
|
||||
have plenty."""
|
||||
where, params = [], []
|
||||
if company:
|
||||
where.append("company_key = ?")
|
||||
params.append(company_key(company))
|
||||
where.append("company LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(company))
|
||||
if place:
|
||||
where.append("place_key = ?")
|
||||
params.append(place_key(place))
|
||||
where.append("place LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(place))
|
||||
if function:
|
||||
where.append("function = ?")
|
||||
params.append(function)
|
||||
if remote:
|
||||
where.append("remote = ?")
|
||||
params.append(remote)
|
||||
if days is not None:
|
||||
where.append("first_seen >= ?")
|
||||
params.append(_iso(self.clock() - timedelta(days=days)))
|
||||
for word in (q or "").split():
|
||||
where.append("title LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(word))
|
||||
if open_only:
|
||||
where.append("closed_at IS NULL")
|
||||
if hide_muted:
|
||||
where.append("company_key NOT IN "
|
||||
"(SELECT key FROM companies WHERE affinity = -1)")
|
||||
sql = "SELECT * FROM roles"
|
||||
if where:
|
||||
sql += " WHERE " + " AND ".join(where)
|
||||
@@ -287,6 +324,24 @@ class Store:
|
||||
raise KeyError(key)
|
||||
return found
|
||||
|
||||
def open_role_counts(self) -> dict[str, int]:
|
||||
"""`company_key -> open role count`, for the company list's row
|
||||
count. A key with no open roles is simply absent."""
|
||||
return {str(r["company_key"]): int(r["n"]) for r in self._rows(
|
||||
"SELECT company_key, COUNT(*) AS n FROM roles "
|
||||
"WHERE closed_at IS NULL GROUP BY company_key")}
|
||||
|
||||
def company_boards(self) -> dict[str, str]:
|
||||
"""`company_key -> ats host`, read off each company's own
|
||||
subscription. `Subscription.company` is the display name it and the
|
||||
company row were both added with, so `company_key` of one finds the
|
||||
other; a company added by hand with no subscription is simply
|
||||
absent."""
|
||||
boards: dict[str, str] = {}
|
||||
for sub in self.subscriptions(source="ats"):
|
||||
boards.setdefault(company_key(sub.company), sub.board)
|
||||
return boards
|
||||
|
||||
# -------------------------------------------------------- subscriptions
|
||||
|
||||
def subscriptions(self, source: str | None = None,
|
||||
|
||||
Reference in new issue
Block a user