diff --git a/.sops.yaml b/.sops.yaml index 4bf3ffe..891cabd 100644 --- a/.sops.yaml +++ b/.sops.yaml @@ -1,3 +1,3 @@ creation_rules: - path_regex: \.env\..+\.sops$ - age: age1f5002gj4s78jju45jd28kuejtcfhn5cdujz885fl7z2p9ym68pnsgky87a + age: age1f5002gj4s78jju45jd28kuejtcfhn5cdujz885fl7z2p9ym68pnsgky87a,age1wjepykv3glvsrtegu25tevg7vyn3ngpl607u3yjc9ucay04s045s796msw diff --git a/web/scripts/dev_run.sh b/web/scripts/dev_run.sh index d81d5ea..4820af0 100755 --- a/web/scripts/dev_run.sh +++ b/web/scripts/dev_run.sh @@ -165,8 +165,8 @@ echo "" echo "Press Ctrl-C to stop all processes." echo "" -run_with_label "$COLOR_APP" "app " uv run python -m padelnomics.app -run_with_label "$COLOR_WORKER" "worker" uv run python -m padelnomics.worker +run_with_label "$COLOR_APP" "app " uv run python -u -m padelnomics.app +run_with_label "$COLOR_WORKER" "worker" uv run python -u -m padelnomics.worker run_with_label "$COLOR_CSS" "css " make css-watch wait diff --git a/web/src/padelnomics/analytics.py b/web/src/padelnomics/analytics.py index 05d38ff..5513ca2 100644 --- a/web/src/padelnomics/analytics.py +++ b/web/src/padelnomics/analytics.py @@ -51,9 +51,13 @@ async def fetch_analytics(sql: str, params: list | None = None) -> list[dict[str return [] def _run() -> list[dict]: - rel = _conn.execute(sql, params or []) - cols = [d[0] for d in rel.description] - return [dict(zip(cols, row)) for row in rel.fetchall()] + cur = _conn.cursor() + try: + rel = cur.execute(sql, params or []) + cols = [d[0] for d in rel.description] + return [dict(zip(cols, row)) for row in rel.fetchall()] + finally: + cur.close() try: return await asyncio.to_thread(_run) diff --git a/web/src/padelnomics/content/__init__.py b/web/src/padelnomics/content/__init__.py index b9be927..e86ad7e 100644 --- a/web/src/padelnomics/content/__init__.py +++ b/web/src/padelnomics/content/__init__.py @@ -367,7 +367,7 @@ async def generate_articles( """INSERT INTO published_scenarios (slug, title, location, country, venue_type, ownership, court_config, state_json, calc_json, created_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(slug) DO UPDATE SET state_json = excluded.state_json, calc_json = excluded.calc_json, @@ -474,13 +474,14 @@ async def generate_articles( md_dir.mkdir(parents=True, exist_ok=True) (md_dir / f"{article_slug}.md").write_text(body_md) - # Upsert article in SQLite — keyed by (url_path, language) + # Upsert article — keyed by (url_path, language). + # Single statement: no SELECT round-trip, no per-row commit. await db.execute( """INSERT INTO articles (url_path, slug, title, meta_description, country, region, status, published_at, template_slug, language, date_modified, seo_head, created_at) - VALUES (?, ?, ?, ?, ?, ?, 'published', ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, 'published', ?, ?, ?, ?, ?, ?) ON CONFLICT(url_path, language) DO UPDATE SET title = excluded.title, meta_description = excluded.meta_description,