Compare commits

..

1 commit

Author SHA1 Message Date
Izalia Mae 5ae3d55e44 Merge branch 'sql' into 'master'
Draft: switch database backend to sql

See merge request pleroma/relay!53
2024-01-24 06:21:49 +00:00
4 changed files with 7 additions and 18 deletions

View file

@ -17,12 +17,7 @@ if typing.TYPE_CHECKING:
def get_database(config: Config, migrate: bool = True) -> tinysql.Database: def get_database(config: Config, migrate: bool = True) -> tinysql.Database:
if config.db_type == "sqlite": 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)
db = tinysql.Database.sqlite(
config.sqlite_path,
connection_class = Connection,
check_same_thread = False
)
elif config.db_type == "postgres": elif config.db_type == "postgres":
db = tinysql.Database.postgres( db = tinysql.Database.postgres(

View file

@ -180,11 +180,6 @@ class Message(ApMessage):
class Response(AiohttpResponse): class Response(AiohttpResponse):
# AiohttpResponse.__len__ method returns 0, so bool(response) always returns False
def __bool__(self) -> bool:
return True
@classmethod @classmethod
def new(cls: type[Response], def new(cls: type[Response],
body: str | bytes | dict = '', body: str | bytes | dict = '',

View file

@ -17,7 +17,7 @@ cache = LRUCache(1024)
def person_check(actor: str, software: str) -> bool: def person_check(actor: str, software: str) -> bool:
# pleroma and akkoma may use Person for the actor type for some reason # pleroma and akkoma may use Person for the actor type for some reason
# akkoma changed this in 3.6.0 # akkoma changed this in a 3.6.0
if software in {'akkoma', 'pleroma'} and actor.id == f'https://{actor.domain}/relay': if software in {'akkoma', 'pleroma'} and actor.id == f'https://{actor.domain}/relay':
return False return False
@ -62,7 +62,7 @@ async def handle_follow(view: ActorView) -> None:
with view.database.connection() as conn: with view.database.connection() as conn:
# reject if software used by actor is banned # reject if software used by actor is banned
if conn.get_software_ban(software): if view.config.is_banned_software(software):
view.app.push_message( view.app.push_message(
view.actor.shared_inbox, view.actor.shared_inbox,
Message.new_response( Message.new_response(
@ -141,7 +141,7 @@ async def handle_undo(view: ActorView) -> None:
return return
with view.database.connection() as conn: with view.database.connection() as conn:
if not conn.del_inbox(view.actor.id): if not conn.del_inbox(view.actor.inbox):
logging.verbose( logging.verbose(
'Failed to delete "%s" with follow ID "%s"', 'Failed to delete "%s" with follow ID "%s"',
view.actor.id, view.actor.id,

View file

@ -9,7 +9,6 @@ from aputils.errors import SignatureFailureError
from aputils.misc import Digest, HttpDate, Signature from aputils.misc import Digest, HttpDate, Signature
from aputils.objects import Nodeinfo, Webfinger, WellKnownNodeinfo from aputils.objects import Nodeinfo, Webfinger, WellKnownNodeinfo
from pathlib import Path from pathlib import Path
from urllib.parse import urlparse
from . import __version__ from . import __version__
from . import logger as logging from . import logger as logging
@ -113,11 +112,11 @@ class ActorView(View):
async def post(self, request: Request) -> Response: async def post(self, request: Request) -> Response:
if response := await self.get_post_data(): if (response := await self.get_post_data()):
return response return response
with self.database.connection() as conn: with self.database.connection() as conn:
self.instance = conn.get_inbox(self.actor.shared_inbox) self.instance = conn.get_inbox(self.actor.inbox)
config = conn.get_config_all() config = conn.get_config_all()
## reject if the actor isn't whitelisted while the whiltelist is enabled ## reject if the actor isn't whitelisted while the whiltelist is enabled
@ -171,7 +170,7 @@ class ActorView(View):
self.actor = await self.client.get(self.signature.keyid, sign_headers = True) self.actor = await self.client.get(self.signature.keyid, sign_headers = True)
if not self.actor: if self.actor is None:
# ld signatures aren't handled atm, so just ignore it # ld signatures aren't handled atm, so just ignore it
if self.message.type == 'Delete': if self.message.type == 'Delete':
logging.verbose('Instance sent a delete which cannot be handled') logging.verbose('Instance sent a delete which cannot be handled')