From 1ce90a297a74601e0fabc22722056d03c943f0d2 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Thu, 3 Aug 2023 20:59:22 +0800 Subject: [PATCH] [perf] process relates inbox object --- app/boxes.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index aff5a6f..aa0e1ea 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -38,17 +38,17 @@ def build_object_id(id) -> str: async def get_outbox_object( - db_session: AsyncSession, - ap_id: str, -) -> OutboxObject | None : + db_session: AsyncSession, + ap_id: str, +) -> OutboxObject | None: return ( ( await db_session.execute( select(OutboxObject) .where(OutboxObject.ap_id == ap_id) .options( - joinedload(models.OutboxObject.relates_to_inbox_object).options( - joinedload(models.InboxObject.actor), + joinedload(OutboxObject.relates_to_inbox_object).options( + joinedload(InboxObject.actor), ), ) ) @@ -58,6 +58,23 @@ async def get_outbox_object( ) +async def get_inbox_object( + db_session: AsyncSession, + ap_id: str, +) -> InboxObject | None: + return ( + await db_session.execute( + select(InboxObject) + .where(InboxObject.ap_id == ap_id) + .options( + joinedload(InboxObject.actor), + joinedload(InboxObject.relates_to_inbox_object), + joinedload(InboxObject.relates_to_outbox_object), + ) + ) + ).scalar_one_or_none() + + async def save_incoming( db_session: AsyncSession, payload: dict, @@ -103,12 +120,21 @@ async def process_incoming( db_session, ap_object["object"]["id"], ) + relates_to_inbox_object = await get_inbox_object( + db_session, + ap_object["object"]["id"] + ) else: if ap_object["object"].startswith(BASE_URL): relates_to_outbox_object = await get_outbox_object( db_session, ap_object["object"], ) + relates_to_inbox_object = await get_inbox_object( + db_session, + ap_object["object"] + ) + def build_object( object, @@ -221,6 +247,8 @@ async def process_incoming( relates_to_inbox_object=relates_to_inbox_object, ): return True + elif "Create" == ap_object["type"]: + pass return False