fix: 트랙 API DB 접속 버그 수정 (context manager)

- kcgdb.get_conn()을 with문 없이 사용 → cursor 에러
- with kcgdb.get_conn() as conn: 으로 수정
- 디버그 로그 추가 (rows 수, track 매칭 수, vessel_store 크기)
- 결과: 47 vessels, 47 with track data (25567#1 그룹)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
htlee 2026-03-31 09:03:33 +09:00
부모 6ea394d120
커밋 8631546142

파일 보기

@ -85,24 +85,26 @@ def get_correlation_tracks(
from cache.vessel_store import vessel_store
try:
conn = kcgdb.get_conn()
cur = conn.cursor()
with kcgdb.get_conn() as conn:
cur = conn.cursor()
# Get correlated vessels from ALL active models
cur.execute("""
SELECT s.target_mmsi, s.target_type, s.target_name,
s.current_score, m.name AS model_name
FROM kcg.gear_correlation_scores s
JOIN kcg.correlation_param_models m ON s.model_id = m.id
WHERE s.group_key = %s
AND s.current_score >= %s
AND m.is_active = TRUE
ORDER BY s.current_score DESC
""", (group_key, min_score))
# Get correlated vessels from ALL active models
cur.execute("""
SELECT s.target_mmsi, s.target_type, s.target_name,
s.current_score, m.name AS model_name
FROM kcg.gear_correlation_scores s
JOIN kcg.correlation_param_models m ON s.model_id = m.id
WHERE s.group_key = %s
AND s.current_score >= %s
AND m.is_active = TRUE
ORDER BY s.current_score DESC
""", (group_key, min_score))
rows = cur.fetchall()
cur.close()
conn.close()
rows = cur.fetchall()
cur.close()
logger.info('correlation tracks: group_key=%r, min_score=%s, rows=%d',
group_key, min_score, len(rows))
if not rows:
return {'groupKey': group_key, 'vessels': []}
@ -131,6 +133,9 @@ def get_correlation_tracks(
# Get tracks from vessel_store
tracks = vessel_store.get_vessel_tracks(mmsis, hours)
with_tracks = sum(1 for m in mmsis if m in tracks and len(tracks[m]) > 0)
logger.info('correlation tracks: %d unique mmsis, %d with track data, vessel_store._tracks has %d entries',
len(mmsis), with_tracks, len(vessel_store._tracks))
# Build response
vessels = []