Fix concurrent checklist sync and consistent actions

This commit is contained in:
Codex 2026-10-04 20:19:03 +01:00
parent a33f7a297d
commit 8d5a94d7fa
10 changed files with 124 additions and 20 deletions

12
app.py
View file

@ -9,6 +9,7 @@ import logging
import mimetypes
import re
import sqlite3
from contextlib import closing
from datetime import datetime, timezone
from http import HTTPStatus
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@ -38,7 +39,7 @@ class Store:
return connection
def initialize(self) -> None:
with self.connect() as db:
with closing(self.connect()) as db, db:
db.executescript(
"""
CREATE TABLE IF NOT EXISTS checks (
@ -56,7 +57,7 @@ class Store:
)
def snapshot(self) -> dict:
with self.connect() as db:
with closing(self.connect()) as db, db:
revision = int(
db.execute("SELECT value FROM metadata WHERE key = 'revision'").fetchone()[0]
)
@ -75,7 +76,7 @@ class Store:
def set_check(self, item_id: str, checked: bool, user: str) -> dict:
changed_at = utc_now()
with self.connect() as db:
with closing(self.connect()) as db, db:
db.execute("BEGIN IMMEDIATE")
db.execute(
"""
@ -206,7 +207,10 @@ class Handler(BaseHTTPRequestHandler):
}
self.send_header("Content-Type", f"{content_type}; charset=utf-8" if textual else content_type)
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "no-cache" if target.name == "index.html" else "public, max-age=3600")
# Source filenames are intentionally stable. Always revalidate them so
# two household clients cannot run different interaction code for an
# hour after a deployment.
self.send_header("Cache-Control", "no-cache" if textual else "public, max-age=3600")
self.end_headers()
self.wfile.write(body)