Skip to content

_bulk_update_scrape_cache_fk()

Class: JobsAustriaCacheSynchronizer
File: jobs_austria_cache_synchronizer.py ยท line 95

CASE-based bulk UPDATE of scrape_cache.fk_job_id.

Signature

Parameters to_update
Returns not annotated
Async No
Visibility Private

Implementation

def _bulk_update_scrape_cache_fk(self, to_update: pd.DataFrame):
    """CASE-based bulk UPDATE of scrape_cache.fk_job_id."""
    case_parts, params, ids = [], {}, []
    for i, row in enumerate(to_update.itertuples()):
        s_key, j_key = f"s{i}", f"j{i}"
        case_parts.append(f"WHEN id = :{s_key} THEN :{j_key}")
        params[s_key] = row.scrape_cache_id
        params[j_key] = int(row.jobs_id)
        ids.append(row.scrape_cache_id)

    params["id_list"] = tuple(ids)
    query = text(
        f"UPDATE scrape_cache SET fk_job_id = CASE {' '.join(case_parts)} END "
        f"WHERE id IN :id_list"
    )
    with self.engine.begin() as conn:
        conn.execute(query, params)