feat: a database connection pool behind DB_POOL (off in production)
Every db.connect() opened a new Postgres connection; with DB_POOL=on each process keeps a psycopg_pool pool (DB_POOL_SIZE, default 20, 10 s acquisition timeout, dropped connections replaced) with the same commit/rollback contract. Production stays off until switched in Portainer; the local stack and CI run with it on. Two nested acquisitions that ran on every board load and in audits now reuse the caller's connection. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
10
app/tiny.py
10
app/tiny.py
@@ -323,10 +323,12 @@ class TinyAuth:
|
||||
operator = self._claim(c, state)
|
||||
return self.authorize_url(operator, offline=False)
|
||||
|
||||
def status(self):
|
||||
with self.connect() as c:
|
||||
row = c.execute('''SELECT connected_by,connected_at,refresh_expires_at,updated_at,offline,
|
||||
refresh_failed_at,refused_at FROM dtf_local.provider_tokens WHERE provider='tiny' ''').fetchone()
|
||||
def status(self, c=None):
|
||||
if c is None:
|
||||
with self.connect() as c:
|
||||
return self.status(c)
|
||||
row = c.execute('''SELECT connected_by,connected_at,refresh_expires_at,updated_at,offline,
|
||||
refresh_failed_at,refused_at FROM dtf_local.provider_tokens WHERE provider='tiny' ''').fetchone()
|
||||
if not row:
|
||||
return {'connected': False}
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
Reference in New Issue
Block a user