Avoid raw runway history rebuild on hot path
This commit is contained in:
@@ -161,6 +161,53 @@ def test_overlay_builds_amsc_runway_history_from_raw_store():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_overlay_skips_raw_store_when_runway_history_already_has_points():
|
||||||
|
class FakeDB:
|
||||||
|
def get_latest_raw_observation(self, source, city):
|
||||||
|
assert (source, city) == ("amsc_awos", "chengdu")
|
||||||
|
return {
|
||||||
|
"observed_at": "2026-06-15T11:08:00+00:00",
|
||||||
|
"station_code": "ZUUU",
|
||||||
|
"payload": {
|
||||||
|
"source": "amsc_awos",
|
||||||
|
"icao": "ZUUU",
|
||||||
|
"temp_c": 25.4,
|
||||||
|
"observation_time": "2026-06-15T11:08:00+00:00",
|
||||||
|
"runway_obs": {
|
||||||
|
"point_temperatures": [
|
||||||
|
{
|
||||||
|
"runway": "02L/20R",
|
||||||
|
"target_runway_max": 25.4,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def list_raw_observation_history(self, source, city, *, minutes=60, limit=1000):
|
||||||
|
raise AssertionError("raw store history should not be read for populated runway history")
|
||||||
|
|
||||||
|
result = overlay_latest_amsc_observation(
|
||||||
|
FakeDB(),
|
||||||
|
"chengdu",
|
||||||
|
{
|
||||||
|
"name": "chengdu",
|
||||||
|
"temp_symbol": "°C",
|
||||||
|
"runway_plate_history": {
|
||||||
|
"02L/20R": [
|
||||||
|
{"time": "2026-06-15T11:04:00+00:00", "temp": 25.6},
|
||||||
|
{"time": "2026-06-15T11:06:00+00:00", "temp": 25.5},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["runway_plate_history"]["02L/20R"][-1] == {
|
||||||
|
"time": "2026-06-15T11:08:00+00:00",
|
||||||
|
"temp": 25.4,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_overlay_uses_latest_success_when_newer_status_row_has_no_observation():
|
def test_overlay_uses_latest_success_when_newer_status_row_has_no_observation():
|
||||||
class FakeDB:
|
class FakeDB:
|
||||||
def get_latest_raw_observation(self, source, city):
|
def get_latest_raw_observation(self, source, city):
|
||||||
|
|||||||
@@ -313,6 +313,16 @@ def _append_amsc_runway_history_from_raw_store(
|
|||||||
city: str,
|
city: str,
|
||||||
payload: dict[str, Any],
|
payload: dict[str, Any],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
existing_history = payload.get("runway_plate_history")
|
||||||
|
if isinstance(existing_history, dict):
|
||||||
|
existing_points = [
|
||||||
|
len(points)
|
||||||
|
for points in existing_history.values()
|
||||||
|
if isinstance(points, list)
|
||||||
|
]
|
||||||
|
if max(existing_points or [0]) > 1:
|
||||||
|
return False
|
||||||
|
|
||||||
lister = getattr(db, "list_raw_observation_history", None)
|
lister = getattr(db, "list_raw_observation_history", None)
|
||||||
if not callable(lister):
|
if not callable(lister):
|
||||||
return False
|
return False
|
||||||
@@ -321,7 +331,6 @@ def _append_amsc_runway_history_from_raw_store(
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.debug("latest AMSC raw history overlay skipped city={}: {}", city, exc)
|
logger.debug("latest AMSC raw history overlay skipped city={}: {}", city, exc)
|
||||||
return False
|
return False
|
||||||
existing_history = payload.get("runway_plate_history")
|
|
||||||
payload["runway_plate_history"] = deepcopy(existing_history) if isinstance(existing_history, dict) else {}
|
payload["runway_plate_history"] = deepcopy(existing_history) if isinstance(existing_history, dict) else {}
|
||||||
changed = False
|
changed = False
|
||||||
for row in rows if isinstance(rows, list) else []:
|
for row in rows if isinstance(rows, list) else []:
|
||||||
|
|||||||
Reference in New Issue
Block a user