Optimize signal read paths and enforce score invariants
Deploy / lint (push) Successful in 7s
Deploy / test (push) Successful in 1m11s
Deploy / deploy (push) Successful in 37s

This commit is contained in:
2026-07-11 13:36:59 +02:00
parent fdc49d0e28
commit 25364f8e99
12 changed files with 357 additions and 35 deletions
+20 -2
View File
@@ -13,6 +13,7 @@ from datetime import datetime, timezone
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import insert_for_session
from app.exceptions import NotFoundError
from app.models.fundamental import FundamentalData
from app.models.score import DimensionScore
@@ -67,7 +68,7 @@ async def store_fundamental(
existing.unavailable_fields_json = unavailable_fields_json
record = existing
else:
record = FundamentalData(
stmt = insert_for_session(db, FundamentalData).values(
ticker_id=ticker.id,
pe_ratio=pe_ratio,
revenue_growth=revenue_growth,
@@ -77,7 +78,24 @@ async def store_fundamental(
fetched_at=now,
unavailable_fields_json=unavailable_fields_json,
)
db.add(record)
await db.execute(
stmt.on_conflict_do_update(
index_elements=["ticker_id"],
set_={
"pe_ratio": stmt.excluded.pe_ratio,
"revenue_growth": stmt.excluded.revenue_growth,
"earnings_surprise": stmt.excluded.earnings_surprise,
"market_cap": stmt.excluded.market_cap,
"next_earnings_date": stmt.excluded.next_earnings_date,
"fetched_at": stmt.excluded.fetched_at,
"unavailable_fields_json": stmt.excluded.unavailable_fields_json,
},
)
)
result = await db.execute(
select(FundamentalData).where(FundamentalData.ticker_id == ticker.id)
)
record = result.scalar_one()
# Mark fundamental dimension score as stale if it exists
# TODO: Use DimensionScore service when built