catalog

Helpers that compute and cache the catalog file’s SHA-256 so the FastAPI middleware can attach a weak ETag to every /apps* response. The hash changes exactly when the catalog deploys (typically once per day on the refresh schedule) and never otherwise, which makes it a perfect cache key for both Cloudflare and revalidating clients.

catalog_db_path() Path | None[source]

On-disk path of the SQLite catalog, or None for in-memory databases.

Tests run against sqlite+aiosqlite:///:memory:; there’s no file to hash, so callers treat None as “no ETag” and skip cache headers.

Return type:

Path | None

hash_catalog_file(path: Path) str[source]

One-shot SHA-256 of the catalog DB file, ~1 second for a 65 MB DB.

Parameters:

path (Path)

Return type:

str

recompute_catalog_sha(app: FastAPI) str | None[source]

Re-hash the catalog and store it on app.state.catalog_sha.

Returns the new hash, or None for an in-memory / missing DB (state is left untouched in that case). Called at startup and after any live write so the /apps* ETag reflects the current data instead of pinning to the hash captured when the process booted.

Parameters:

app (FastAPI)

Return type:

str | None