Harden score endpoint with resilient fallback and sqlite race/lock handling

This commit is contained in:
Oliver 2026-02-16 07:46:43 +01:00
parent 198bbd89ab
commit e67d8ad0f5
No known key found for this signature in database
3 changed files with 80 additions and 14 deletions

View file

@ -6,15 +6,17 @@ DB_PATH = BASE_DIR / "data" / "staysense.db"
def get_conn() -> sqlite3.Connection:
conn = sqlite3.connect(DB_PATH)
conn = sqlite3.connect(DB_PATH, timeout=10)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys = ON")
conn.execute("PRAGMA busy_timeout = 10000")
return conn
def init_db() -> None:
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
with get_conn() as conn:
conn.execute("PRAGMA journal_mode = WAL")
conn.executescript(
"""
CREATE TABLE IF NOT EXISTS spot (