@ -10,7 +10,7 @@ from typing import List, Optional
from fastapi import APIRouter , Depends , HTTPException , Query , Response
from sqlalchemy . ext . asyncio import AsyncSession
from app . core . database import get_db
from app . core . database import get_db , AsyncSessionLocal
from app . schemas . filing import (
BulkExhibitItem ,
BulkExhibitRequest ,
@ -290,27 +290,29 @@ async def get_exhibit_bulk(
async def _fetch_one ( item : dict ) - > BulkExhibitItem :
accession_number = item . get ( " accession_number " , " " )
exhibit_type = item . get ( " exhibit_type " , " EX-99.1 " )
try :
result = await asyncio . wait_for (
sec_filings_service . get_exhibit_content ( db , accession_number , exhibit_type ) ,
timeout = 30 ,
)
return BulkExhibitItem (
accession_number = accession_number ,
exhibit_type = exhibit_type ,
success = True ,
content = result [ " content " ] ,
content_type = result . get ( " content_type " ) ,
filename = result . get ( " filename " ) ,
url = result . get ( " url " ) ,
)
except Exception as e :
return BulkExhibitItem (
accession_number = accession_number ,
exhibit_type = exhibit_type ,
success = False ,
error = str ( e ) ,
)
# Each concurrent call gets its own DB session to avoid session contention
async with AsyncSessionLocal ( ) as session :
try :
result = await asyncio . wait_for (
sec_filings_service . get_exhibit_content ( session , accession_number , exhibit_type ) ,
timeout = 30 ,
)
return BulkExhibitItem (
accession_number = accession_number ,
exhibit_type = exhibit_type ,
success = True ,
content = result [ " content " ] ,
content_type = result . get ( " content_type " ) ,
filename = result . get ( " filename " ) ,
url = result . get ( " url " ) ,
)
except Exception as e :
return BulkExhibitItem (
accession_number = accession_number ,
exhibit_type = exhibit_type ,
success = False ,
error = str ( e ) ,
)
raw = await asyncio . gather ( * [ _fetch_one ( item ) for item in request . items ] , return_exceptions = True )
results : List [ BulkExhibitItem ] = [ ]