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