Serve recent stages from SQLite with configurable background refresh
Magent CI/CD / verify (push) Successful in 1m51s
Magent CI/CD / deploy-prod (push) Skipped
Magent CI/CD / deploy-beta (push) Skipped

This commit is contained in:
2026-09-13 16:18:30 +12:00
parent dcd8082c8d
commit d7e5c75cb1
8 changed files with 115 additions and 24 deletions
+16 -1
View File
@@ -187,6 +187,7 @@ def _has_secure_bootstrap_admin_credentials() -> bool:
def init_db() -> None:
with _connect() as conn:
conn.execute("CREATE TABLE IF NOT EXISTS request_stage_cache (request_id INTEGER PRIMARY KEY, source_updated TEXT, ready INTEGER NOT NULL, checked_at REAL NOT NULL)")
conn.execute("""CREATE TABLE IF NOT EXISTS user_duplicate_repairs (
id INTEGER PRIMARY KEY AUTOINCREMENT, kept_user_id INTEGER NOT NULL,
archive_json TEXT NOT NULL, repaired_by TEXT NOT NULL, repaired_at TEXT NOT NULL)""")
@@ -855,6 +856,7 @@ def save_action(
) -> None:
created_at = datetime.now(timezone.utc).isoformat()
with _connect() as conn:
conn.execute('UPDATE request_stage_cache SET checked_at = 0 WHERE request_id = ?', (request_id,))
conn.execute(
"""
INSERT INTO actions (request_id, action_id, label, status, message, created_at)
@@ -2879,7 +2881,7 @@ def get_cached_requests_since(since_iso: str) -> list[Dict[str, Any]]:
rows = conn.execute(
"""
SELECT request_id, media_id, media_type, status, title, year, requested_by,
requested_by_norm, requested_by_id, created_at
requested_by_norm, requested_by_id, created_at, updated_at
FROM requests_cache
WHERE created_at >= ?
ORDER BY created_at DESC, request_id DESC
@@ -2900,6 +2902,7 @@ def get_cached_requests_since(since_iso: str) -> list[Dict[str, Any]]:
"requested_by_norm": row[7],
"requested_by_id": row[8],
"created_at": row[9],
"updated_at": row[10],
}
)
return results
@@ -4027,3 +4030,15 @@ def cleanup_history(days: int) -> Dict[str, int]:
(cutoff,),
).rowcount
return {"actions": actions, "snapshots": snapshots}
def get_request_stage_cache():
with _connect() as conn:
return {row[0]: {'source_updated': row[1], 'ready': bool(row[2]), 'checked_at': row[3]}
for row in conn.execute('SELECT request_id, source_updated, ready, checked_at FROM request_stage_cache')}
def save_request_stage_cache(rows):
with _connect() as conn:
conn.executemany('INSERT OR REPLACE INTO request_stage_cache (request_id, source_updated, ready, checked_at) VALUES (?, ?, ?, ?)', rows)
conn.execute('DELETE FROM request_stage_cache WHERE request_id NOT IN (SELECT request_id FROM requests_cache)')