@ -25,6 +25,10 @@ logger = logging.getLogger(__name__)
# Maximum exhibit content size (5 MB)
# Maximum exhibit content size (5 MB)
MAX_EXHIBIT_SIZE = 5 * 1024 * 1024
MAX_EXHIBIT_SIZE = 5 * 1024 * 1024
# Limit concurrent background reindex tasks to prevent event-loop saturation
# when bulk scans trigger hundreds of simultaneous SEC EDGAR fetches.
_BACKGROUND_REINDEX_SEMAPHORE = asyncio . Semaphore ( 3 )
class SECFilingsService :
class SECFilingsService :
SUPPORTED_FORM_TYPES : Set [ str ] = {
SUPPORTED_FORM_TYPES : Set [ str ] = {
@ -247,6 +251,7 @@ class SECFilingsService:
self , ticker : str , form_types : Optional [ Set [ str ] ] , lock : asyncio . Lock
self , ticker : str , form_types : Optional [ Set [ str ] ] , lock : asyncio . Lock
) - > None :
) - > None :
""" Re-index a stale ticker in the background with its own DB session. """
""" Re-index a stale ticker in the background with its own DB session. """
async with _BACKGROUND_REINDEX_SEMAPHORE :
async with lock :
async with lock :
try :
try :
from app . core . database import AsyncSessionLocal
from app . core . database import AsyncSessionLocal