Merge branch 'gates-any'
# Conflicts: # README.md # app/storage/store.py
This commit is contained in:
commit
6779dda888
10 files changed
+143
-28
No files matched your search
+16
-8
@@ -23,7 +23,7 @@ from desk.models import Item
|
||||
from app.models import (
|
||||
AFFINITY, REMOTE, STATUSES, Agent, Application, ApplicationEvent, Candidate,
|
||||
Company, Gate, Limits, Role, ScoredRole, Subscription, Weights, company_key,
|
||||
country_of, place_key, title_key,
|
||||
country_of, place_key, remote_of, title_key,
|
||||
)
|
||||
from app.storage import schema
|
||||
|
||||
@@ -291,6 +291,7 @@ class Store:
|
||||
}
|
||||
row |= {name: str(raw.get(name) or "") for name in _RAW_TEXT}
|
||||
row["country"] = row["country"] or country_of(place)
|
||||
row["remote"] = row["remote"] or remote_of(place)
|
||||
row |= {name: _int_or_none(raw.get(name)) for name in _RAW_INT}
|
||||
|
||||
keep_filled = ("company", "company_key", "place_key", "remote", "description",
|
||||
@@ -608,14 +609,21 @@ class Store:
|
||||
"UPDATE roles SET closed_at = ? WHERE subscription_id = ? AND closed_at IS NULL",
|
||||
(self.now(), subscription_id))
|
||||
|
||||
def backfill_country(self) -> int:
|
||||
"""Fill `country` from `place` on every role that has none, the way
|
||||
`upsert_role` does for a new one. Returns how many it filled."""
|
||||
rows = self._rows("SELECT uid, place FROM roles WHERE country = '' AND place != ''")
|
||||
filled = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
|
||||
def backfill_from_place(self) -> int:
|
||||
"""Fill `country` and `remote` from `place` on every role that has
|
||||
none, the way `upsert_role` does for a new one, so a word added to the
|
||||
lookups reaches the roles already stored. Returns how many columns it
|
||||
filled."""
|
||||
rows = self._rows("SELECT uid, place FROM roles "
|
||||
"WHERE place != '' AND (country = '' OR remote = '')")
|
||||
countries = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
|
||||
remotes = [(mode, r["uid"]) for r in rows if (mode := remote_of(r["place"]))]
|
||||
with self.transaction() as conn:
|
||||
conn.executemany("UPDATE roles SET country = ? WHERE uid = ?", filled)
|
||||
return len(filled)
|
||||
conn.executemany("UPDATE roles SET country = ? WHERE uid = ? AND country = ''",
|
||||
countries)
|
||||
conn.executemany("UPDATE roles SET remote = ? WHERE uid = ? AND remote = ''",
|
||||
remotes)
|
||||
return len(countries) + len(remotes)
|
||||
|
||||
# -------------------------------------------------------------- extract
|
||||
|
||||
|
||||
Reference in new issue
Block a user