perf(realestate): run_listing_matching 단일 conn+배치 + POST /listings/rematch(MOLIT없이 즉시 재판정)

- get_market_deals_for에 optional conn 파라미터 추가(재사용 시 open/close 안 함, 기존 단건 호출부는 불변)
- bulk_upsert_listing_matches 추가(listing_matches 다건 upsert, 단일 connection)
- run_listing_matching이 listings 조회+매물별 market_deals 조회+최종 upsert를 단일 _conn()으로 처리
  (기존: 269건 매물마다 개별 _conn() 3회 → 병목)
- POST /api/realestate/listings/rematch: MOLIT 재수집 없이 기존 listings+market_deals로 즉시 재판정
  (알림 미발송, 즉시 피드백용)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EqCYBhvTcdeCTUDX3RhWx9
This commit is contained in:
2026-07-10 13:56:45 +09:00
parent b471d2c455
commit 4097c95286
6 changed files with 230 additions and 33 deletions

View File

@@ -286,6 +286,18 @@ def api_listing_matches():
return {"matches": get_listing_matches()}
@app.post("/api/realestate/listings/rematch")
def api_listings_rematch():
"""MOLIT 재수집 없이 기존 listings+market_deals로 즉시 재판정(즉시 피드백용, 알림 미발송)."""
with match_notify_lock:
run_listing_matching()
matches = get_listing_matches()
passed = sum(1 for m in matches if m.get("passed"))
judged = sum(1 for m in matches if m.get("passed")
and (m.get("safety_tier") or m.get("valuation_tier")) not in (None, "보류"))
return {"total": len(matches), "passed": passed, "judged": judged}
@app.post("/api/realestate/safety-check")
def api_safety_check(req: SafetyCheckRequest):
deals = get_market_deals_for(req.dong_code, req.complex_name, req.area,