[perf] check duplicat accept respond
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
SouthFox 2023-07-31 05:55:08 +08:00
parent f9f398a207
commit 849f8de6f9

View file

@ -22,7 +22,7 @@ from urllib.parse import urlparse
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy import delete from sqlalchemy import delete
from sqlalchemy.orm import joinedload from sqlalchemy.orm import joinedload
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from loguru import logger from loguru import logger
from uuid import uuid4 from uuid import uuid4
from datetime import datetime from datetime import datetime
@ -166,9 +166,15 @@ async def process_incoming(
).unique().scalar_one_or_none() ).unique().scalar_one_or_none()
if "Accept" == ap_object["type"]: if "Accept" == ap_object["type"]:
inbox_object = build_object(ap_object) try:
db_session.add(inbox_object) inbox_object = build_object(ap_object)
await db_session.flush() 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) await db_session.refresh(inbox_object)
following = models.Following( following = models.Following(