fix(news): per-bill URL dedup + lazy re-fetch on bill detail load

- Drop global unique constraint on news_articles.url; replace with
  (bill_id, url) so the same article can appear for multiple bills
- news_fetcher dedup now scoped to bill_id instead of global URL
- Bill detail endpoint triggers a background news fetch when no
  articles are stored, so gnews articles surface on next load

Migration 0009.

Co-Authored-By: Jack Levy
This commit is contained in:
Jack Levy
2026-03-01 00:43:10 -05:00
parent a66b5b4bcb
commit 50f93468db
4 changed files with 43 additions and 4 deletions

View File

@@ -109,6 +109,15 @@ async def get_bill(bill_id: str, db: AsyncSession = Depends(get_db)):
detail.latest_brief = bill.briefs[0]
if bill.trend_scores:
detail.latest_trend = bill.trend_scores[0]
# Trigger a background news refresh if no articles are stored yet
if not bill.news_articles:
try:
from app.workers.news_fetcher import fetch_news_for_bill
fetch_news_for_bill.delay(bill_id)
except Exception:
pass
return detail