From 849f8de6f98930e9a4c6129c5ad30c6d4cda8ddd Mon Sep 17 00:00:00 2001 From: SouthFox Date: Mon, 31 Jul 2023 05:55:08 +0800 Subject: [PATCH] [perf] check duplicat accept respond --- app/boxes.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index 0793a97..a5aa1b0 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -22,7 +22,7 @@ from urllib.parse import urlparse from sqlalchemy import select from sqlalchemy import delete from sqlalchemy.orm import joinedload -from sqlalchemy.exc import IntegrityError +from sqlalchemy.exc import IntegrityError from loguru import logger from uuid import uuid4 from datetime import datetime @@ -166,9 +166,15 @@ async def process_incoming( ).unique().scalar_one_or_none() if "Accept" == ap_object["type"]: - inbox_object = build_object(ap_object) - db_session.add(inbox_object) - await db_session.flush() + try: + inbox_object = build_object(ap_object) + db_session.add(inbox_object) + await db_session.flush() + except IntegrityError: + logger.warning("Duplicate accept respond?") + await db_session.rollback() + return True + await db_session.refresh(inbox_object) following = models.Following(