From cf3d19f8456933691033046b34578f67c1160e28 Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Tue, 21 Jan 2025 13:22:42 +0100 Subject: [PATCH] APSW best practice --- src/itn_api/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/itn_api/api.py b/src/itn_api/api.py index 4d071a3..bcb24ea 100644 --- a/src/itn_api/api.py +++ b/src/itn_api/api.py @@ -79,14 +79,21 @@ ] +def _enable_best_practice(connection: sqlite.Connection): + """Enable aspw best practice.""" + apsw.bestpractice.connection_wal(connection) + apsw.bestpractice.library_logging() + + @asynccontextmanager async def lifespan(app: FastAPI): """Load the database connection for the life of the app.s""" db_path = Path(os.environ["DATABASE_PATH"]) logger.info("validator database: %s", db_path) app.state.connection = apsw.Connection( - str(db_path), flags=apsw.SQLITE_OPEN_READONLY + str(db_path), flags=apsw.SQLITE_OPEN_NOMUTEX | apsw.SQLITE_OPEN_READONLY ) + _enable_best_practice(app.state.connection) app.state.kupo_url = os.environ["KUPO_URL"] app.state.kupo_port = os.environ["KUPO_PORT"] yield