From 603d88acaeee7691814522569d491d6b44a74f10 Mon Sep 17 00:00:00 2001 From: savsis Date: Thu, 10 Sep 2026 22:24:52 +0500 Subject: [PATCH] perf: indices on hot query columns, WAL+NORMAL synchronous for write throughput Co-Authored-By: Claude Sonnet 5 --- db.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db.py b/db.py index 8951f25..b16ecfd 100644 --- a/db.py +++ b/db.py @@ -87,6 +87,14 @@ CREATE TABLE IF NOT EXISTS nodes ( enabled INTEGER NOT NULL DEFAULT 1, created_at TEXT NOT NULL ); + +CREATE INDEX IF NOT EXISTS idx_subs_active_expires ON subscriptions (active, expires_at); +CREATE INDEX IF NOT EXISTS idx_subs_tg_id ON subscriptions (tg_id); +CREATE INDEX IF NOT EXISTS idx_subs_node ON subscriptions (node); +CREATE INDEX IF NOT EXISTS idx_devices_tg_id ON devices (tg_id); +CREATE INDEX IF NOT EXISTS idx_payments_status ON payments (status); +CREATE INDEX IF NOT EXISTS idx_gift_codes_used_by ON gift_codes (used_by); +CREATE INDEX IF NOT EXISTS idx_admin_sessions_expires ON admin_sessions (expires_at); """ _NEW_NODE_COLUMNS = { @@ -124,6 +132,7 @@ def get_conn(): conn.row_factory = sqlite3.Row conn.execute("PRAGMA foreign_keys = ON") conn.execute("PRAGMA journal_mode = WAL") + conn.execute("PRAGMA synchronous = NORMAL") try: yield conn conn.commit()