Commit Graph

9 Commits

Author SHA1 Message Date
Sam Dornan
9a19d94ec5 fix(backend): type DML row counts from Session.execute for mypy (#4718) 2026-09-22 18:24:12 -04:00
Georges-Antoine Assi
21d9a7f3c6 refactor(db): give the pool recycle sentinel one home
An operator's `0` means "off", but SQLAlchemy gates recycling on
`_recycle > -1`, so a literal 0 recycles on every checkout: a fresh
connect and auth handshake per pool checkout. Mapping it to -1 is
therefore load-bearing, but doing it at the engine left the value
defined in `config` and corrected in `base_handler`, so a second
consumer could reasonably pass the raw constant and reintroduce the
footgun. Fold the mapping into the constant.

Also drop the `wait_timeout` figure the comment attributed to MariaDB.
Its default is 28800s; 600s is a value some hosts lower it to, not a
MariaDB one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 10:48:54 -04:00
Georges-Antoine Assi
6b2ca96397 fix(db): recycle pooled connections before the server drops them
The engine sets `pool_pre_ping` but no `pool_recycle`, so a connection
the database closed for being idle is still handed out, and the ping on
that half-closed socket blocks the worker until TCP gives up: tens of
seconds to minutes of an unresponsive API for every request that draws
it, while a fresh connection to the same server answers instantly.

Default to 300s, under the lowest `wait_timeout` MariaDB is commonly
configured with, and make it settable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 20:25:36 -04:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Georges-Antoine Assi
8ed107336f only print queries once 2025-08-21 22:34:07 -04:00
Georges-Antoine Assi
03e2bac425 fix ordering rows in table view 2025-03-23 19:35:53 -04:00
Georges-Antoine Assi
0607323005 log SQL queries and exec time in dev mode 2025-03-22 09:49:13 -04:00
Michael Manganiello
a85c84a7d4 misc: Use single SQLAlchemy engine and session maker
As recommended by SQLAlchemy [1], this change makes a single
instantiation of the database engine and session maker, instead of one
entity per handler.

It also uses the provided `URL` constructor to better define the
database URL structure.

[1] https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage
2024-08-21 09:56:28 -03:00
Georges-Antoine Assi
9ad28f3294 more refactoring again 2024-05-05 16:32:40 -04:00