perf(realestate): market_deals 배치 upsert(단일 conn)로 collect 속도 개선

This commit is contained in:
2026-07-10 13:50:35 +09:00
parent 8e28ce9ae5
commit b471d2c455
3 changed files with 43 additions and 5 deletions

View File

@@ -997,6 +997,28 @@ def upsert_market_deal(data: Dict[str, Any]) -> None:
VALUES ({','.join(':'+c for c in cols)})""", d)
def bulk_upsert_market_deals(rows: List[Dict[str, Any]]) -> int:
"""market_deals 다건 INSERT OR IGNORE (단일 connection). area=None은 skip(무용/bloat 방지).
저장시도 건수 반환. 기존 upsert_market_deal과 동일 dedup(ux_market_deals_dedup 인덱스)."""
cols = ("house_type", "dong_code", "dong", "complex_name", "area", "deal_type",
"deposit", "monthly_rent", "sale_amount", "deal_ym", "floor", "source")
payload = []
for data in rows:
if data.get("area") is None:
continue
d = {c: data.get(c) for c in cols}
d["source"] = data.get("source") or "molit"
payload.append(tuple(d[c] for c in cols))
if not payload:
return 0
with _conn() as conn:
conn.executemany(
f"INSERT OR IGNORE INTO market_deals ({','.join(cols)}) VALUES ({','.join(['?'] * len(cols))})",
payload,
)
return len(payload)
def get_market_deals_for(dong_code, complex_name, area, deal_type, months=6) -> List[Dict[str, Any]]:
with _conn() as conn:
def _query(cn):