Дополнить описание перенесённой схемы и ограничений lab2

This commit is contained in:
2026-11-13 01:33:49 +03:00
parent 4322edcbec
commit 27055b6076
4 changed files with 24 additions and 1 deletions
+1
View File
@@ -7,6 +7,7 @@ from psycopg.rows import dict_row
def connect():
# shortcut: one connection per request; add a bounded pool before load testing.
dsn = Path(os.environ['DATABASE_URL_FILE']).read_text().strip()
return psycopg.connect(dsn, connect_timeout=3, row_factory=dict_row,
options='-c statement_timeout=5000 -c timezone=UTC')
+1
View File
@@ -157,6 +157,7 @@ class Handler(BaseHTTPRequestHandler):
return 201, dict(session, token=token, token_type='Bearer', user={k: user[k] for k in ('id', 'username', 'display_name', 'created_at')})
token = self.credentials('Bearer')
token_digest = hashlib.sha256(token.encode()).digest()
# shortcut: expired rows remain; add scheduled cleanup for a long-lived deployment.
actor = db.execute('SELECT user_id FROM sessions WHERE token_hash=%s AND expires_at > clock_timestamp()', (token_digest,)).fetchone()
require(actor is not None, 401, 'unauthorized')
actor = actor['user_id']