Compare commits

...

5 commits

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

See merge request pleroma/relay!53
2024-01-25 00:55:57 +00:00
Izalia Mae b59ead5d05 fix handle_follow and handle_undo 2024-01-24 19:55:11 -05:00
Izalia Mae b8aae4c1bb use correct url when fetching inbox data 2024-01-24 19:28:15 -05:00
Izalia Mae 85a4797e68 make sure bool(Response) returns True 2024-01-24 19:24:27 -05:00
Izalia Mae c2aa8c48bb ignore thread warnings in the sqlite backend for now 2024-01-24 19:20:27 -05:00
4 changed files with 18 additions and 7 deletions

View file

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

View file

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

View file

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

View file

@ -9,6 +9,7 @@ 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
@ -112,11 +113,11 @@ class ActorView(View):
async def post(self, request: Request) -> Response:
if (response := await self.get_post_data()):
if response := await self.get_post_data():
return response
with self.database.connection() as conn:
self.instance = conn.get_inbox(self.actor.inbox)
self.instance = conn.get_inbox(self.actor.shared_inbox)
config = conn.get_config_all()
## reject if the actor isn't whitelisted while the whiltelist is enabled
@ -170,7 +171,7 @@ class ActorView(View):
self.actor = await self.client.get(self.signature.keyid, sign_headers = True)
if self.actor is None:
if not self.actor:
# ld signatures aren't handled atm, so just ignore it
if self.message.type == 'Delete':
logging.verbose('Instance sent a delete which cannot be handled')