Skip to main content

canonicalise_windows_path_keys

Re-key the cache's file paths to their canonical spelling on Windows.

On Windows, file paths used as cache keys are case-folded by fs_utils.canonical_path_key. A cache can hold keys that are not: one file under \\IMG-SERVER-01\Scans\… and \\Img-Server-01\Scans\…, with its prediction under one spelling and a calculation made under the other, which found no prediction. Nothing else removes such rows: the inventory prune keeps a row whose file still opens, the inference and calculation partitions are never pruned, and the patient API serves every scan_eligibility row. This migration re-keys them in place, so nothing is re-indexed or re-inferred.

  • Clearing, once, before anything is re-keyed. A calculation row is deleted, and its file's wave-ledger rows with it so the next sweep recomputes it, when it is a calculation_error: row, or when its file has a prediction from the model the table is computed from under another spelling but none under its own. Such a row would never be recomputed on its own: its prediction is older than it, so the staleness check treats it as current.
  • Re-keying, table by table. Rows whose keys collapse to one canonical key are reduced to one: a row without an error before one with an error, then the newest. The survivors' path columns are folded, and so are the file ids in ehr_data.file_ids_json.
  • Only values that look like Windows paths (\\server\share\… or X:\…) are folded (fs_utils.canonical_key_if_path). An ehr:<id> wave-ledger key, a database connection string in file_metadata, and source_path (the root as configured, which the walk compares exactly) are left alone.

It never holds the cache for long. Rows to change are found with reads, and written in transactions of at most _ROWS_PER_TRANSACTION rows. The runner holds the cache's migration lock, so a second process waits for it to finish (see cache.migrations.run_pending) and no process works on a half re-keyed cache. Progress is recorded, so a run that stops is resumed.

Off Windows nothing is folded, so it does nothing. A second run changes nothing.

Module​

Functions​

apply​

def apply(cache: CacheProtocol) ‑> int:

Re-key every Windows file path in the cache to its canonical spelling.

Arguments

  • cache: The cache backend.

Returns The number of rows deleted or rewritten. Always 0 off Windows.