From ed9d423ca391afb088fc49a528df2dc79245f026 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sat, 27 Jan 2024 00:59:08 -0500 Subject: [PATCH] update tinysql and set min/max db connections per thread --- relay.spec | 1 + relay/database/__init__.py | 4 ++-- relay/http_client.py | 1 + relay/views.py | 1 - requirements.txt | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/relay.spec b/relay.spec index 535e5fe..8510cd8 100644 --- a/relay.spec +++ b/relay.spec @@ -32,6 +32,7 @@ exe = EXE( a.datas, [], name='activityrelay', + icon=None, debug=False, bootloader_ignore_signals=False, strip=False, diff --git a/relay/database/__init__.py b/relay/database/__init__.py index ede8556..8e79200 100644 --- a/relay/database/__init__.py +++ b/relay/database/__init__.py @@ -17,11 +17,11 @@ if typing.TYPE_CHECKING: def get_database(config: Config, migrate: bool = True) -> tinysql.Database: if config.db_type == "sqlite": - # todo: remove check_same_thread when tinysql stores connections per thread db = tinysql.Database.sqlite( config.sqlite_path, connection_class = Connection, - check_same_thread = False + min_connections = 2, + max_connections = 10 ) elif config.db_type == "postgres": diff --git a/relay/http_client.py b/relay/http_client.py index f461843..5040059 100644 --- a/relay/http_client.py +++ b/relay/http_client.py @@ -143,6 +143,7 @@ class HttpClient: async def post(self, url: str, message: Message) -> None: await self.open() + # todo: cache inboxes to avoid opening a db connection with get_app().database.connection() as conn: instance = conn.get_inbox(url) diff --git a/relay/views.py b/relay/views.py index 456fc56..8b84c02 100644 --- a/relay/views.py +++ b/relay/views.py @@ -9,7 +9,6 @@ from aputils.errors import SignatureFailureError from aputils.misc import Digest, HttpDate, Signature from aputils.objects import Nodeinfo, Webfinger, WellKnownNodeinfo from pathlib import Path -from urllib.parse import urlparse from . import __version__ from . import logger as logging diff --git a/requirements.txt b/requirements.txt index cc6fc4d..43ebfe4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ aputils@https://git.barkshark.xyz/barkshark/aputils/archive/0.1.6a.tar.gz cachetools>=5.2.0 click>=8.1.2 pyyaml>=6.0 -tinysql@https://git.barkshark.xyz/barkshark/tinysql/archive/0.2.1.tar.gz +tinysql@https://git.barkshark.xyz/barkshark/tinysql/archive/0.2.2a.tar.gz